package com.lan.schedule;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.Icon;
import android.media.MediaMetadataRetriever;
import android.media.MediaPlayer;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.os.PowerManager;
import android.os.StrictMode;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.text.method.TransformationMethod;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URI;
import java.nio.channels.FileChannel;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cz.msebera.android.httpclient.HttpRequest;
import cz.msebera.android.httpclient.HttpResponse;
import cz.msebera.android.httpclient.NameValuePair;
import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity;
import cz.msebera.android.httpclient.client.methods.CloseableHttpResponse;
import cz.msebera.android.httpclient.client.methods.HttpGet;
import cz.msebera.android.httpclient.client.methods.HttpPost;
import cz.msebera.android.httpclient.client.methods.HttpUriRequest;
import cz.msebera.android.httpclient.client.protocol.HttpClientContext;
import cz.msebera.android.httpclient.cookie.Cookie;
import cz.msebera.android.httpclient.impl.client.CloseableHttpClient;
import cz.msebera.android.httpclient.impl.client.HttpClients;
import cz.msebera.android.httpclient.message.BasicNameValuePair;
import cz.msebera.android.httpclient.util.EntityUtils;
import cz.msebera.httpclient.android.BuildConfig;

public class MainActivity extends Activity implements View.OnClickListener {
    //  @SuppressLint("WrongViewCast")
//    TextView textview = (TextView) LayoutInflater.from(MainActivity.this).inflate(R.layout.notification_small, null).findViewById(R.id.a);
    private String url_safecode = "http://jwzx.usc.edu.cn:8924/jsxsd/verifycode.servlet"; // 验证码
    private Map<String, String> cookie;
    private String rc;

    class PicThread extends Thread {
        @Override
        public void run() {
            Connection.Response response = null;
            try {
                response = Jsoup.connect(url_safecode).ignoreContentType(true) // 获取图片需设置忽略内容类型
                        .userAgent("Mozilla").method(Connection.Method.GET).timeout(3000).execute();
                cookie = response.cookies();
                byte[] bytes = response.bodyAsBytes();
                Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                Message message = new Message();
                message.what = 0x123;
                message.obj = bitmap;
                handler_rc.sendMessage(message);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    ImageView imageView_rc;
    Handler handler_rc = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0x123) {
                imageView_rc.setImageBitmap((Bitmap) msg.obj);
            }
        }
    };

    /**
     * Main2Activity
     */
    public void wlu(String url) {
        Uri uri = Uri.parse(url);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }

    class MyWeb extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);//在这里设置对应的操作
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
        }
    }

    CheckBox[] cch = new CheckBox[25];
    final Dialog[] dlgqj = new Dialog[1];
    int[] idbx = {R.id.c1, R.id.c2, R.id.c3, R.id.c4, R.id.c5, R.id.c6, R.id.c7, R.id.c8, R.id.c9, R.id.c10, R.id.c11, R.id.c12, R.id.c13, R.id.c14, R.id.c15, R.id.c16, R.id.c17, R.id.c18, R.id.c19, R.id.c20, R.id.c21, R.id.c22, R.id.c23, R.id.c24, R.id.c25};

    class boxc implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            if (v.getId() != nowdc) {
                nowdc = v.getId();
            } else ;
            int at = 0;
            for (int i = 0; i < 25; i++) {
                if (nowdc == idbx[i]) {
                    at = i + 1;
                    break;
                }
            }
//            tezh.setText("第" + at + "周");
            make(0, at);
            dlgqj[0].cancel();
        }
    }

    TextView tezh;
    int nowdc = 0;
    String name1[] = new String[50];
    String loc[] = new String[50];
    int week[][] = new int[50][30];
    int we[] = new int[50];
    int day[] = new int[50];
    int jie[] = new int[50];
    int wend;
    long ww = 0;
    long bben;
    private static final String[] m = {"第1周", "第2周", "第3周", "第4周", "第5周", "第6周", "第7周", "第8周", "第9周", "第10周", "第11周", "第12周", "第13周", "第14周", "第15周", "第16周", "第17周", "第18周", "第19周", "第20周", "第21周", "第22周", "第23周", "第24周", "第25周"};
    //    private Spinner spinner;
    private ArrayAdapter<String> adapter;
    String TAG = "MainActivity ";
    String str1[] = new String[36];
    int[] g2i = new int[36];
    public int id4[] = {R.id.aa, R.id.ab, R.id.af, R.id.ag, R.id.ak, R.id.al, R.id.ap, R.id.aq, R.id.au, R.id.av, R.id.aw, R.id.ax, R.id.ay, R.id.ar, R.id.as, R.id.at, R.id.am, R.id.an, R.id.ao, R.id.ah, R.id.ai, R.id.aj, R.id.ac, R.id.ad, R.id.ae};
    public int id2[] = {R.id.ca, R.id.aa, R.id.ab, R.id.ac, R.id.ad, R.id.ae, R.id.ba, R.id.cf, R.id.af, R.id.ag, R.id.ah, R.id.ai, R.id.aj, R.id.bf, R.id.ck, R.id.ak, R.id.al, R.id.am, R.id.an, R.id.ao, R.id.bk, R.id.cp, R.id.ap, R.id.aq, R.id.ar, R.id.as, R.id.at, R.id.bp, R.id.cu, R.id.au, R.id.av, R.id.aw, R.id.ax, R.id.ay, R.id.bu};
    TextView te1;
    GradientDrawable drawable2 = new GradientDrawable();
    GradientDrawable drawable3 = new GradientDrawable();
    GradientDrawable drawable4 = new GradientDrawable();
    GradientDrawable drawable5 = new GradientDrawable();
    GradientDrawable drawable6 = new GradientDrawable();
    GradientDrawable drawable7 = new GradientDrawable();
    GradientDrawable drawable8 = new GradientDrawable();
    GradientDrawable drawable9 = new GradientDrawable();
    GradientDrawable drawable10 = new GradientDrawable();
    GradientDrawable drawable11 = new GradientDrawable();
    GradientDrawable drawable12 = new GradientDrawable();
    GradientDrawable drawable13 = new GradientDrawable();
    GradientDrawable drawable14 = new GradientDrawable();
    GradientDrawable drawable15 = new GradientDrawable();
    GradientDrawable drawable16 = new GradientDrawable();
    GradientDrawable drawable17 = new GradientDrawable();
    GradientDrawable drawable18 = new GradientDrawable();
    GradientDrawable drawable19 = new GradientDrawable();
    GradientDrawable drawable20 = new GradientDrawable();
    GradientDrawable drawable21 = new GradientDrawable();
    GradientDrawable drawable22 = new GradientDrawable();
    GradientDrawable drawable23 = new GradientDrawable();
    GradientDrawable drawable24 = new GradientDrawable();
    GradientDrawable drawable25 = new GradientDrawable();
    GradientDrawable drawable26 = new GradientDrawable();
    GradientDrawable drawable51 = new GradientDrawable();
    GradientDrawable drawable52 = new GradientDrawable();
    GradientDrawable drawable53 = new GradientDrawable();
    GradientDrawable drawable54 = new GradientDrawable();
    GradientDrawable drawable55 = new GradientDrawable();
    GradientDrawable drawable56 = new GradientDrawable();
    GradientDrawable drawable57 = new GradientDrawable();
    GradientDrawable drawable58 = new GradientDrawable();
    GradientDrawable drawable59 = new GradientDrawable();
    GradientDrawable drawable50 = new GradientDrawable();
    GradientDrawable drawable1[] = {drawable2, drawable3, drawable4, drawable5, drawable6, drawable7, drawable8, drawable9, drawable10, drawable11, drawable12, drawable13, drawable14, drawable15, drawable16, drawable17, drawable18, drawable19, drawable20, drawable21, drawable22, drawable23, drawable24, drawable25, drawable26, drawable51, drawable52, drawable53, drawable54, drawable55, drawable56, drawable57, drawable58, drawable59, drawable50};
    BitmapDrawable bbb;

    /**
     * Main2Activity
     */

    final static String loginUrl1 = "http://ids.xidian.edu.cn/authserver/login?service=http%3A%2F%2Fjwxt.xidian.edu.cn%2Fcaslogin.jsp";

    final static String classInforURL = "http://jwxt.xidian.edu.cn/xkAction.do?actionType=6";
    int flag1 = 1;
    private EditText mEditTextUserName;
    private EditText mEditTextPassWord;
    TextView mTextViewUserName;
    TextView mTextViewPassWord;
    TextView text1;
    private String mUserName;
    private String mPassWord;
    private boolean isHideFirst = true;
    String mJSESSION;
    String mClassInfo;
    Dialog dlg15;
    private ImageView displayPassword;
    private Button simpleNoti;
    private Button zj;
    private Button ben;
    private Button last;
    private Button next;
    private Button diy;
    private Button bc;
    private Button normalNoti;
    private Button progressNoti;
    private Button btnNoti;
    private Button btnCustom;
    String channelId = "my channel"; //通知id
    String name = "渠道名字";
    TextView tv_rgb;

    public static void addShortCut(Context context) {
        ShortcutManager shortcutManager = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            shortcutManager = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (shortcutManager.isRequestPinShortcutSupported()) {
                Intent shortcutInfoIntent = new Intent(context, MainActivity.class);
                shortcutInfoIntent.setAction(Intent.ACTION_VIEW); //action必须设置，不然报错

                ShortcutInfo info = new ShortcutInfo.Builder(context, "The only id")
                        .setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
                        .setShortLabel("Short Label")
                        .setIntent(shortcutInfoIntent)
                        .build();

                //当添加快捷方式的确认弹框弹出来时，将被回调
                PendingIntent shortcutCallbackIntent = PendingIntent.getBroadcast(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_IMMUTABLE);
                shortcutManager.requestPinShortcut(info, shortcutCallbackIntent.getIntentSender());
            }
        }

    }

    public static void createSystemSwitcherShortCut(Context context) {
        final Intent addIntent = new Intent(
                "com.android.launcher.action.INSTALL_SHORTCUT");
        final Parcelable icon = Intent.ShortcutIconResource.fromContext(
                context, R.drawable.bg1); // 获取快捷键的图标
        addIntent.putExtra("duplicate", false);
        final Intent myIntent = new Intent(context,
                MainActivity.class);
        myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "777");// 快捷方式的标题
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 快捷方式的图标
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);// 快捷方式的动作
        context.sendBroadcast(addIntent);
    }

    protected void ppp() {

        text1.setText("tttt");
    }

    public static void openBattart(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            if (pm != null && !pm.isIgnoringBatteryOptimizations(context.getPackageName())) {
                //1.进入系统电池优化设置界面,把当前APP加入白名单
                //startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));

                //2.弹出系统对话框,把当前APP加入白名单(无需进入设置界面)
                //在manifest添加权限
                Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
                intent.setData(Uri.parse("package:" + context.getPackageName()));
                try {
                    context.startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void startService() {
        Intent intent = new Intent(this, AlarmService.class);
        startService(intent);
    }

    private void checkNeedPermissions() {
        //6.0以上需要动态申请权限
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED
                || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            //多个权限一起申请
            ActivityCompat.requestPermissions(this, new String[]{
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.READ_EXTERNAL_STORAGE
            }, 1);
        }
    }

    //    ImageView im1;
//    ImageView im2;
    int fla = -9;
    int flaj = -9;
    int ba = 0xffff0000;
    int sh = 0x55ffffff;
    int fo = 0xff000000;
    int alp = 100;
    GradientDrawable.Orientation or[] = {GradientDrawable.Orientation.TL_BR, GradientDrawable.Orientation.BR_TL, GradientDrawable.Orientation.BL_TR, GradientDrawable.Orientation.TR_BL, GradientDrawable.Orientation.TOP_BOTTOM, GradientDrawable.Orientation.BOTTOM_TOP, GradientDrawable.Orientation.LEFT_RIGHT, GradientDrawable.Orientation.RIGHT_LEFT};
    GradientDrawable.Orientation or1 = or[5];
    int grcolor[] = new int[6];
    int colorcan[][] = new int[6][3];
    int ifcolor[] = new int[6];
    int top = 0;
    int now = 0;
    int flazjm = -1;
    ImageView bacg;
    String vpa;

    public void reads() {
        SharedPreferences nw_qq = getSharedPreferences("nowtop_xml", MODE_PRIVATE);
        String now2 = nw_qq.getString("now", "0");
        String top2 = nw_qq.getString("top", "0");
        now = Integer.parseInt(now2);
        top = Integer.parseInt(top2);
    }

    public void fr() {
        colorcan[3][0] = 0xffeeeeee;
        for (int i = 0; i < 6; i++) {
            ifcolor[i] = 0;
            grcolor[i] = 5;
        }
        colorcan[5][0] = 0x00FFFFFF;
        colorcan[4][0] = 0xFFFFFFFF;
        colorcan[0][0] = 0xFF000000;
        colorcan[1][0] = 0xFF880000;
        colorcan[2][0] = 0x55ffffff;
    }

    public void setc() {
        try {
            String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
            File file = new File(strFilePath, "th1.txt");//在创建文件
            file.canRead();
            InputStream ff = null;
            ff = new FileInputStream(file);

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(ff));

            fla = Integer.parseInt(bufferedReader.readLine());
            alp = Integer.parseInt(bufferedReader.readLine());
            for (int y = 0; y < 6; y++) {
                ifcolor[y] = Integer.parseInt(bufferedReader.readLine());
                grcolor[y] = Integer.parseInt(bufferedReader.readLine());
                for (int x = 0; x < 3; x++) {
                    colorcan[y][x] = Integer.parseInt(bufferedReader.readLine());
                }
            }
            flazjm = Integer.parseInt(bufferedReader.readLine());
            vpa = bufferedReader.readLine();
            ff.close();
            bufferedReader.close();
//            ba = ba1;
//            sh = sh1;
//            fo = fo1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        //  System.out.println(fla+","+ba);
    }

    public int dpToPx(int dps) {
        return Math.round(getResources().getDisplayMetrics().density * dps);
    }

    TextView mon;
    TextView da1;
    TextView da2;
    TextView da3;
    TextView da4;
    TextView da5;
    TextView da6;
    TextView da7;
    int j;

    public int make(int f6, long d) {
        int re = 0;
        j = 0;
//        String name1[] = new String[50];
//        String loc[] = new String[50];
//        int week[][] = new int[50][30];
//        int we[] = new int[50];
//        int day[] = new int[50];
//        int jie[] = new int[50];
        try {
            FileInputStream fileInputStream = openFileInput("test.txt");
            FileChannel f1 = fileInputStream.getChannel();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
            j = Integer.parseInt(bufferedReader.readLine());
            for (int i = 1; i < j; i++) {
                name1[i] = bufferedReader.readLine();
                loc[i] = bufferedReader.readLine();
                jie[i] = Integer.parseInt(bufferedReader.readLine());
                day[i] = Integer.parseInt(bufferedReader.readLine());
                we[i] = Integer.parseInt(bufferedReader.readLine());
                for (int p = 1; p <= we[i]; p++) {
                    week[i][p] = Integer.parseInt(bufferedReader.readLine());
                }
            }
            f1.close();
            bufferedReader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        /**/
//        String ddd=""+j+" ";
//        for (int i = 1; i < j; i++) {
//ddd=ddd+name1[i]+" "+loc[i]+" "+jie[i]+" "+day[i]+" "+we[i]+" ";
//            for (int p = 1; p <= we[i]; p++) {
//                ddd=ddd+week[i][p]+" ";
//            }
//        }
//        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
//        ClipData m = ClipData.newPlainText("Label", ddd);
//        cm.setPrimaryClip(m);
//        Toast to = Toast.makeText(MainActivity.this, "已复制课程数据到剪切板，请您到QQ粘贴发给开发者", Toast.LENGTH_SHORT);
//        to.setGravity(Gravity.CENTER, 0, 0);
//        to.show();
        /**/
        long wee = 0;
        String date = null;
        try {
            String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
            File file = new File(strFilePath, "date.txt");//在创建文件
            file.canRead();
            InputStream ff = null;
            ff = new FileInputStream(file);

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(ff));
            date = bufferedReader.readLine();
            ff.close();
            bufferedReader.close();
//            ba = ba1;
//            sh = sh1;
//            fo = fo1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (f6 == 1) {
            String eTime = date;
            long nd = 1000 * 24 * 60 * 60 * 7;// 一天的毫秒数
            long diff = 0;
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date curDate = new Date(System.currentTimeMillis());
            String nowtime = simpleDateFormat.format(curDate);
            if (date != null) {
                try {
                    diff = simpleDateFormat.parse(nowtime).getTime() - simpleDateFormat.parse(eTime).getTime();
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }

            wee = diff / nd + 1;// 计算周数
            //wee=2;
            if (diff < 0) {
                re = 1;
                wee = wee - 1;
            }
            bben = wee;
            ww = wee;
        } else {
            wee = d;
            ww = wee;
        }
        Calendar c = Calendar.getInstance();
//        int day = c.get(Calendar.DAY_OF_MONTH);
//        int month = c.get(Calendar.MONTH);
        int tda = (int) (wee - bben);
        c.add(Calendar.DATE, tda * 7);
        int weekt = c.get(Calendar.DAY_OF_WEEK);
        String[] daa = new String[7];
        int month;
//        daa[week - 1] = String.valueOf(day);
        int yxd = 0;
        c.add(Calendar.DATE, 1 - weekt);
        month = c.get(Calendar.MONTH);
        daa[0] = String.valueOf(c.get(Calendar.DAY_OF_MONTH));
        for (int p = 1; p < 7; p++) {
            c.add(Calendar.DATE, 1);
            yxd = c.get(Calendar.DAY_OF_MONTH);
            daa[p] = String.valueOf(yxd);
            if (c.get(Calendar.DAY_OF_MONTH) == 1) {
                daa[p] = (c.get(Calendar.MONTH) + 1) + "月";
            }
        }
//        int df = 0;
//        df = day - week + 1;
        mon.setText((month + 1) + "\n月");
        da1.setText("日\n" + daa[0]);
        da2.setText("一\n" + daa[1]);
        da3.setText("二\n" + daa[2]);
        da4.setText("三\n" + daa[3]);
        da5.setText("四\n" + daa[4]);
        da6.setText("五\n" + daa[5]);
        da7.setText("六\n" + daa[6]);
        for (int i = 1; i < 36; i++) {
            int fl = 0;
            int ji;
            ji = i / 7 + 1;
            if (i % 7 == 0) ji = ji - 1;
            int da;
            da = i % 7;
//            if (da == 0) da = 5;
            outterLoop:
            for (int g = 1; g < j; g++) {

                if (day[g] == da && jie[g] == ji) {
                    for (int p = 1; p <= we[g]; p++) {
                        if (wee == week[g][p]) {
                            fl = 1;
                            str1[i] = name1[g] + loc[g];
                            g2i[i] = g;
                            break outterLoop;
                        }
                    }
                }
            }
            if (fl == 0) str1[i] = "";
        }
        if (ifcolor[0] == 0) {

            for (int o = 1; o < 36; o++) {
                te1 = findViewById(id2[o - 1]);
                te1.setText(str1[o]);
                te1.setTextColor(colorcan[0][0]);
                //layout.setTextViewText(id2[o-1],str1[o]);
                //notificationLayoutExpanded.setTextColor(id2[o-1],0xFFFFFF);
                if (str1[o].equals("")) {
                    te1.setBackgroundColor(0x00ffffff);
                } else {
                    //notificationLayoutExpanded.setImageViewResource(id1[o-1],R.drawable.radius_border);
                    te1.setBackground(drawable1[o - 1]);
                }
            }
        } else {
            for (int o = 1; o < 36; o++) {
                te1 = findViewById(id2[o - 1]);
                te1.setText(Main2Activity.getRadiusGradientSpan(str1[o], colorcan[0][1], colorcan[0][2]));

                //layout.setTextViewText(id2[o-1],str1[o]);
                //notificationLayoutExpanded.setTextColor(id2[o-1],0xFFFFFF);
                if (str1[o].equals("")) {
                    te1.setBackgroundColor(0x00ffffff);
                } else {
                    //notificationLayoutExpanded.setImageViewResource(id1[o-1],R.drawable.radius_border);
                    te1.setBackground(drawable1[o - 1]);
                }
            }
        }
        tezh.setText("第" + ww + "周");
        return re;
    }

    public void getAndroiodScreenProperty() {
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;// 屏幕宽度（像素）
        int height = dm.heightPixels; // 屏幕高度（像素）
        float density = dm.density;//屏幕密度（0.75 / 1.0 / 1.5）
        int densityDpi = dm.densityDpi;//屏幕密度dpi（120 / 160 / 240）
        //屏幕宽度算法:屏幕宽度（像素）/屏幕密度
        int screenWidth = (int) (width / density);//屏幕宽度(dp)
        int screenHeight = (int) (height / density);//屏幕高度(dp)
        Log.e("123", screenWidth + "======" + screenHeight);
    }

    public static Bitmap getAlplaBitmap(Bitmap sourceImg, int number) {

        int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];

        sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg.getWidth(), sourceImg.getHeight());

        number = number * 255 / 100;

        for (int i = 0; i < argb.length; i++) {
            argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF);

        }

        sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), sourceImg.getHeight(), Bitmap.Config.ARGB_8888);

        return sourceImg;

    }

    @SuppressLint("WrongConstant")
    public void upp() {
        reads();
        setc();
        make(1, 0);
        final LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
        ImageView bcg = findViewById(R.id.bacgr);
        final GradientDrawable drawable2 = new GradientDrawable();
        final GradientDrawable drawable212 = new GradientDrawable();
        final GradientDrawable drawable213 = new GradientDrawable();
        drawable2.setShape(GradientDrawable.RECTANGLE);
        drawable2.setGradientType(GradientDrawable.RECTANGLE);
//        drawable2.setCornerRadius(50);
//        drawable2.setColor(ba);
        if (ifcolor[1] == 0) {
            drawable2.setColor(colorcan[1][0]);
            System.out.println(88888);
        } else {
            int[] colors = {colorcan[1][1], colorcan[1][2]};
            drawable2.setColors(colors);
            drawable2.setOrientation(or[grcolor[1]]);
        }
        if (ifcolor[4] == 0)
            drawable212.setColor(colorcan[4][0]);
        else {
            int[] colors = {colorcan[4][1], colorcan[4][2]};
            drawable212.setColors(colors);
            drawable212.setOrientation(or[grcolor[4]]);
        }
//        im1.setImageDrawable(drawable212);
        if (ifcolor[5] == 0)
            drawable213.setColor(colorcan[5][0]);
        else {
            int[] colors = {colorcan[5][1], colorcan[5][2]};
            drawable213.setColors(colors);
            drawable213.setOrientation(or[grcolor[5]]);
        }
//        im2.setImageDrawable(drawable213);
//        Drawable drawable = getResources().getDrawable(R.drawable.bg1);
//
//        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
//
//        Bitmap bitmap = bitmapDrawable.getBitmap();
        Bitmap bitmap = Bitmap.createBitmap(1080, 1738, Bitmap.Config.ARGB_8888);
        bitmap.eraseColor(0xff22737F);

//        bbb = new BitmapDrawable(Main2Activity.toRoundCorner(bitmap, 20));
        bbb = new BitmapDrawable(bitmap);
        if (flazjm != 10) {
            if (flazjm == 8) {
                Bitmap zbit = Bitmap.createBitmap(1080, 2400, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(zbit);
                drawable2.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                drawable2.draw(canvas);
                bcg.setImageBitmap(zbit);

            } else {
                Uri imageUri;
                String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
                imageUri = Uri.fromFile(new File(strFilePath, "landxzjm.png"));
                try {
                    bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
//            bitmap=getAlplaBitmap(bitmap,alp);
//            bbb = new BitmapDrawable(Main2Activity.toRoundCorner(bitmap, 20));
                bbb = new BitmapDrawable(bitmap);
                bcg.setImageBitmap(bitmap);
            }
        }
        if (flazjm == 10) {
            Bitmap bitmap5 = Bitmap.createBitmap(1080, 2400, Bitmap.Config.ARGB_8888);
            bitmap5.eraseColor(0x00000000);
            bacg.setImageBitmap(bitmap5);
            Bitmap bitmapv = getNetVideoBitmap(vpa);
            if (bitmapv != null) {
                videoview.setBackground(new BitmapDrawable(getResources(), bitmapv));
            }//        videoview.setVideoURI(Uri.parse(vpa));
//
//        //播放
//        videoview.start();
//        //循环播放
//        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//            @Override
//            public void onCompletion(MediaPlayer mediaPlayer) {
//                videoview.start();
//                mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
//                    @Override
//                    public boolean onInfo(MediaPlayer mp, int what, int extra) {
//                        return false;
//                    }
//                });
//            }
//        });
            videoview.setVideoURI(Uri.parse(vpa));

            videoview.requestFocus();

            videoview.start();
            videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mediaPlayer) {
                    videoview.start();
                    mediaPlayer.setVolume(0f, 0f);
                    float videoRatio = mediaPlayer.getVideoWidth() / (float) mediaPlayer.getVideoHeight();
                    float screenRatio = videoview.getWidth() / (float)
                            videoview.getHeight();
                    float scaleX = videoRatio / screenRatio;
                    if (scaleX >= 1f) {
                        videoview.setScaleX(scaleX);
                    } else {
                        videoview.setScaleY(1f / scaleX);
                    }
                    mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
                        @Override
                        public boolean onInfo(MediaPlayer mp, int what, int extra) {
                            return false;
                        }
                    });
                }
            });
            videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

                @Override

                public void onPrepared(MediaPlayer mp) {
                    mp.setVolume(0f, 0f);
                    float videoRatio = mp.getVideoWidth() / (float) mp.getVideoHeight();
                    float screenRatio = videoview.getWidth() / (float)
                            videoview.getHeight();
                    float scaleX = videoRatio / screenRatio;
                    if (scaleX >= 1f) {
                        videoview.setScaleX(scaleX);
                    } else {
                        videoview.setScaleY(1f / scaleX);
                    }
                    mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {

                        @Override

                        public boolean onInfo(MediaPlayer mp, int what, int extra) {

                            if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {

                                videoview.setBackgroundColor(Color.TRANSPARENT);

                            }

                            return true;

                        }

                    });

                }

            });
        }
//        else
//            bcg.setImageBitmap(bitmap);
//        colorcan[3][0]=0xFFCCF9FE;
        if (ifcolor[2] == 0) {
            int[] cc = {colorcan[2][0], colorcan[2][0]};
//            int[] cc = {0x00000000, 0x00000000};
            for (int i = 0; i < 35; i++) {
                drawable1[i].setShape(GradientDrawable.RECTANGLE);
                drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
                drawable1[i].setCornerRadius(15);
                drawable1[i].setStroke(3, colorcan[3][0]);
                drawable1[i].setColors(cc);
            }
        } else {
            int[] cs = {colorcan[2][1], colorcan[2][2]};
//            int[] cs = {0x00000000, 0x00000000};
            for (int i = 0; i < 35; i++) {
                drawable1[i].setShape(GradientDrawable.RECTANGLE);
                drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
                drawable1[i].setCornerRadius(15);
                drawable1[i].setStroke(3, colorcan[3][0]);
                drawable1[i].setColors(cs);
                drawable1[i].setOrientation(or[grcolor[2]]);
            }
        }
    }

    public void reload() {
        Intent intent = getIntent();
        overridePendingTransition(0, 0);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        finish();
        overridePendingTransition(0, 0);
        startActivity(intent);
    }

    private Handler handler = new Handler() {
        @SuppressLint("WrongConstant")
        @Override
        public void dispatchMessage(Message msg) {
            Log.v("abc--", "Handler更新MainActivity界面");
            reload();
//            upp();
//            Intent intent = new Intent(MainActivity.this, MainActivity.class);
//            startActivity(intent);
            //MainText.setText("通过handler更新数据");
        }
    };


    private final static int SELECT_PIC = 0x123;

    private void cropFromGallery() {
        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
        File fil = new File(strFilePath, "landx1.png");
//        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file";
//        File file = new File(strFilePath, "ll.png");//在创建文件
        Uri uri = FileProvider.getUriForFile(this, "com.lan.schedule.fileprovider", fil);
        Intent inl = new Intent(Intent.ACTION_PICK, null);
        inl.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
//        inl.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
//        inl.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
//        inl.putExtra("noFaceDetection", true); // no face detection
        startActivityForResult(inl, 8715);
        // TODO Auto-generated method stub
//        String stri= String.valueOf(imageUri);
//        System.out.println(stri);
//System.out.println(uri);
//        Intent intent = new Intent();
//        intent.setAction("com.android.camera.action.CROP");//Pick an item from the data
//        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
//        intent.setDataAndType(uri,"image/*");//从所有图片中进行选择
////        intent.putExtra("crop", "true");//设置为裁切
////        intent.putExtra("aspectX", 344);//裁切的宽比例
////        intent.putExtra("aspectY", 256);//裁切的高比例
////        intent.putExtra("outputX", 344);//裁切的宽度
////        intent.putExtra("outputY", 256);//裁切的高度
////        intent.putExtra("scale", true);//支持缩放
////        intent.putExtra("return-data", false);
//        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
//        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
//        intent.putExtra("noFaceDetection", true); // no face detection
//        startActivityForResult(intent, SELECT_PIC);
    }

    private void getcr(Uri uri1) {
        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
        File fil = new File(strFilePath, "landx1.png");
//        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file";
//        File file = new File(strFilePath, "ll.png");//在创建文件
        Uri uri = FileProvider.getUriForFile(this, "com.lan.schedule.fileprovider", fil);

        Intent intent = new Intent();
        intent.setAction("com.android.camera.action.CROP");//Pick an item from the data
//        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        intent.setDataAndType(uri1, "image/*");//从所有图片中进行选择
        intent.putExtra("crop", "true");//设置为裁切
        intent.putExtra("aspectX", 344);//裁切的宽比例
        intent.putExtra("aspectY", 256);//裁切的高比例
        intent.putExtra("outputX", 2016);//裁切的宽度
        intent.putExtra("outputY", 1500);//裁切的高度
        intent.putExtra("scale", true);//支持缩放
        intent.putExtra("return-data", false);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
        intent.putExtra("noFaceDetection", true); // no face detection
        List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resInfoList) {
            //我用的小米手机 packageName 得到的是：com.miui.gallery
            String packageName = resolveInfo.activityInfo.packageName;
            grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            //注意不是 getPackageName()！！ getPackageName()得到的是app的包名
//            grantUriPermission(getPackageName(), cropUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        ComponentName componentName = intent.resolveActivity(getPackageManager());
        if (componentName != null) {
            startActivityForResult(intent, SELECT_PIC);
        }
    }

    private void czjm() {
        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
        File fil = new File(strFilePath, "landx.png");
//        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file";
//        File file = new File(strFilePath, "ll.png");//在创建文件
        Uri uri = FileProvider.getUriForFile(this, "com.lan.schedule.fileprovider", fil);
//        Intent inl=new Intent(Intent.ACTION_PICK,null);
//        inl.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI,"image/*");
//        inl.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
//        inl.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
//        inl.putExtra("noFaceDetection", true); // no face detection
        // TODO Auto-generated method stub
//        String stri= String.valueOf(imageUri);
//        System.out.println(stri);
//System.out.println(uri);
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_PICK);//Pick an item from the data
//        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        intent.setType("image/*");//从所有图片中进行选择
        intent.putExtra("crop", "true");//设置为裁切
        intent.putExtra("aspectX", 9);//裁切的宽比例
        intent.putExtra("aspectY", 20);//裁切的高比例
        intent.putExtra("outputX", 1080);//裁切的宽度
        intent.putExtra("outputY", 2400);//裁切的高度
        intent.putExtra("scale", true);//支持缩放
        intent.putExtra("return-data", true);
//        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
//        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
//        intent.putExtra("noFaceDetection", true); // no face detection
//        startActivityForResult(intent, SELECT_PIC);
        startActivityForResult(intent, 8716);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        switch (requestCode) {
            case SELECT_PIC:
                if (resultCode == RESULT_OK) {
                    String data1 = "20";
                    String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
                    File cacheFile = new File(strFilePath);
                    // 上级文件不存在，进行文件夹的创建
                    if (!cacheFile.exists()) { // 先根据路径创建文件夹
                        cacheFile.mkdirs();
                    }
                    String filename = "th2.txt";
                    File file = new File(strFilePath, filename);//在创建文件
                    boolean createResult = false;
                    try {
                        if (file.exists()) {
                            file.delete();
                        }
                        createResult = file.createNewFile();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    file.canWrite();
                    OutputStream ff = null;
                    try {
                        ff = new FileOutputStream(file);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    byte[] szBuf = data1.getBytes();
                    try {
                        ff.write(szBuf);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        ff.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                break;
            case 8715:
                getcr(data.getData());
                break;
            case 8716:
                Bitmap bp = data.getParcelableExtra("data");
                File cf = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files", "landxzjm.png");
                FileOutputStream fos = null;
                try {
                    fos = new FileOutputStream(cf);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                bp.compress(Bitmap.CompressFormat.PNG, 100, fos);
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case 55500:
                if (resultCode == RESULT_OK) {
                    Uri uri = data.getData();
                    ContentResolver cr = this.getContentResolver();
                    /** 数据库查询操作。
                     * 第一个参数 uri：为要查询的数据库+表的名称。
                     * 第二个参数 projection ： 要查询的列。
                     * 第三个参数 selection ： 查询的条件，相当于SQL where。
                     * 第三个参数 selectionArgs ： 查询条件的参数，相当于 ？。
                     * 第四个参数 sortOrder ： 结果排序。
                     */
                    Cursor cursor = cr.query(uri, null, null, null, null);
                    if (cursor != null) {
                        if (cursor.moveToFirst()) {
                            // 视频ID:MediaStore.Audio.Media._ID
                            int videoId = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
                            // 视频名称：MediaStore.Audio.Media.TITLE
                            String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
                            // 视频路径：MediaStore.Audio.Media.DATA
                            String videoPath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
                            Toast to = Toast.makeText(MainActivity.this, videoPath, Toast.LENGTH_LONG);
                            to.setGravity(Gravity.CENTER, 0, 0);
                            to.show();
                            // 视频时长：MediaStore.Audio.Media.DURATION
                            int duration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
                            // 视频大小：MediaStore.Audio.Media.SIZE
                            long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));

                            // 视频缩略图路径：MediaStore.Images.Media.DATA
                            String imagePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
                            // 缩略图ID:MediaStore.Audio.Media._ID
                            int imageId = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
                            // 方法一 Thumbnails 利用createVideoThumbnail 通过路径得到缩略图，保持为视频的默认比例
                            // 第一个参数为 ContentResolver，第二个参数为视频缩略图ID， 第三个参数kind有两种为：MICRO_KIND和MINI_KIND 字面意思理解为微型和迷你两种缩略模式，前者分辨率更低一些。
                            Bitmap bitmap1 = MediaStore.Video.Thumbnails.getThumbnail(cr, imageId, MediaStore.Video.Thumbnails.MICRO_KIND, null);

                            // 方法二 ThumbnailUtils 利用createVideoThumbnail 通过路径得到缩略图，保持为视频的默认比例
                            // 第一个参数为 视频/缩略图的位置，第二个依旧是分辨率相关的kind
                            Bitmap bitmap2 = ThumbnailUtils.createVideoThumbnail(imagePath, MediaStore.Video.Thumbnails.MICRO_KIND);
                            // 如果追求更好的话可以利用 ThumbnailUtils.extractThumbnail 把缩略图转化为的制定大小
//                        ThumbnailUtils.extractThumbnail(bitmap, width,height ,ThumbnailUtils.OPTIONS_RECYCLE_INPUT);

                        }
                        cursor.close();
                    }
                }
                break;
            default:
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    boolean[] tfla = new boolean[35];
    Bitmap tbit;
    int txb = 36;

    class tlis implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            final TextView t = (TextView) v;
            int i = 0;
            int ii = t.getId();
            for (; i < 35; i++) {
                if (ii == id2[i]) {
                    break;
                }
            }
            String strte = String.valueOf(t.getText());
            if (strte.equals("") || strte.equals("+")) {
                int xb = 0;
//                for (int i = 0; i < 35; i++) {
//                    if (ii == id2[i]) {
                if (tfla[i]) {
                    t.setBackgroundColor(0x00000000);
                    t.setText("");
                    MyAppliacation.getInstance().setHandler(handler);
                    Intent intent = new Intent(MainActivity.this, tjactivity.class);
                    int day = (i + 1) % 7;
                    intent.putExtra("day", day);
                    int jie = (i + 1) / 7 + 1;
                    if (day == 0) jie = jie - 1;
                    intent.putExtra("g", -2);
                    intent.putExtra("jie", jie);
                    intent.putExtra("name", "");
                    intent.putExtra("loc", "");
                    intent.putExtra("we", 0);
                    intent.putExtra("week", 0);
                    startActivity(intent);
                } else {
                    if (txb == 36 || txb == i) ;
                    else {
                        TextView tem = findViewById(id2[txb]);
                        tem.setText("");
                        tem.setBackgroundColor(0x00000000);
                        tfla[txb] = !tfla[txb];
                    }
                    t.setBackground(drawable1[i]);
                    t.setText("+");
                    txb = i;
                }
                tfla[i] = !tfla[i];
//                        break;
//                    }
//                }
            } else {
                final Dialog dlg;
                final Drawable dr = getResources().getDrawable(R.drawable.radius_border1);
                dlg = new AlertDialog.Builder(MainActivity.this).create();
                dlg.show();//显示对话框
                Window window = dlg.getWindow();//获取对话框窗口\
                window.setGravity(Gravity.CENTER);//设置对话框显示剧中的位置
                window.setContentView(R.layout.ctclass);//设置对话框布局
                window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

                window.setBackgroundDrawable(dr);
                WindowManager.LayoutParams params = dlg.getWindow()
                        .getAttributes();
//                Display display = getWindowManager().getDefaultDisplay();
//                params.width = (int) (dpToPx(344));
//                        params.width=dpToPx(360);
//                params.dimAmount = 0.0f;
                dlg.getWindow().setAttributes(params);
                TextView weekt = window.findViewById(R.id.week);
                TextView dayjie = window.findViewById(R.id.dayjie);
                TextView name = window.findViewById(R.id.name);
                TextView loc12 = window.findViewById(R.id.loc);
                String weeekt = "";
                int endt = week[g2i[i + 1]][1];
                int stt = week[g2i[i + 1]][1];
                for (int k = 2; k <= we[g2i[i + 1]]; k++) {
                    if (week[g2i[i + 1]][k] == endt + 1) endt = endt + 1;
                    else {
                        if (stt == endt) {
                            weeekt = weeekt + "第" + stt + "周 ";
                        } else {
                            weeekt = weeekt + "第" + stt + "-" + endt + "周 ";
                        }
                        stt = week[g2i[i + 1]][k];
                        endt = week[g2i[i + 1]][k];
                    }
                }
                if (stt == endt) {
                    weeekt = weeekt + "第" + stt + "周 ";
                } else {
                    weeekt = weeekt + "第" + stt + "-" + endt + "周 ";
                }
                weekt.setText(weeekt);
                name.setText(name1[g2i[i + 1]]);
                loc12.setText(loc[g2i[i + 1]]);
                String en2ch[] = {"六", "日", "一", "二", "三", "四", "五"};
                dayjie.setText("星期" + en2ch[day[g2i[i + 1]]] + "  第" + jie[g2i[i + 1]] + "节");
                Button del = window.findViewById(R.id.del);
                Button bj = window.findViewById(R.id.bj);
                final int finalI1 = i;
                del.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        final Dialog dlgdel;
                        dlgdel = new AlertDialog.Builder(MainActivity.this).create();
                        dlgdel.show();//显示对话框
                        Window window = dlgdel.getWindow();//获取对话框窗口\
                        window.setGravity(Gravity.CENTER);//设置对话框显示剧中的位置
                        window.setContentView(R.layout.ctdel);//设置对话框布局
                        window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

                        window.setBackgroundDrawable(dr);
                        WindowManager.LayoutParams params = dlgdel.getWindow()
                                .getAttributes();
//                Display display = getWindowManager().getDefaultDisplay();
//                params.width = (int) (dpToPx(344));
//                        params.width=dpToPx(360);
//                params.dimAmount = 0.0f;
                        dlgdel.getWindow().setAttributes(params);
                        Button qd = window.findViewById(R.id.qd);
                        Button qx = window.findViewById(R.id.qx);
                        qx.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                dlgdel.cancel();
                            }
                        });
                        qd.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                int j12 = j - 1;
                                String data = j12 + "\n";
                                for (int i = 1; i < j; i++) {
                                    if (i != g2i[finalI1 + 1]) {
                                        data = data + name1[i] + "\n" + loc[i] + "\n" + jie[i] + "\n" + day[i] + "\n" + we[i] + "\n";
                                        for (int p = 1; p <= we[i]; p++) {
                                            data = data + week[i][p] + "\n";
                                        }
                                    } else ;
                                }
                                try {
                                    FileOutputStream fileOutputStream = openFileOutput("test.txt", 0);
                                    fileOutputStream.write(data.getBytes());
                                    fileOutputStream.close();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                t.setText("");
                                t.setBackgroundColor(0x00000000);
                                dlgdel.cancel();
                                dlg.cancel();
                            }
                        });
                    }
                });
                final int finalI = i;
                bj.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        MyAppliacation.getInstance().setHandler(handler);
                        Intent intent = new Intent(MainActivity.this, tjactivity.class);
                        int day = (finalI + 1) % 7;
                        intent.putExtra("day", day);
                        int jie = (finalI + 1) / 7 + 1;
                        if (day == 0) jie = jie - 1;
                        intent.putExtra("jie", jie);
                        intent.putExtra("g", g2i[finalI + 1]);
                        intent.putExtra("name", name1[g2i[finalI + 1]]);
                        intent.putExtra("loc", loc[g2i[finalI + 1]]);
                        intent.putExtra("we", we[g2i[finalI + 1]]);
                        intent.putExtra("week", week[g2i[finalI + 1]]);
                        startActivity(intent);
                    }
                });
            }
        }
    }

    public static Bitmap getNetVideoBitmap(String videoUrl) {
        Bitmap bitmap = null;
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try {
            //根据url获取缩略图
            retriever.setDataSource(videoUrl, new HashMap());
            //获得第一帧图片
            bitmap = retriever.getFrameAtTime();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } finally {
            retriever.release();
        }
        return bitmap;
    }


    BackVideoView videoview;

    @Override
    protected void onStop() {
        super.onStop();
        videoview.stopPlayback();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        if (flazjm == 10) {
            videoview = (BackVideoView) findViewById(R.id.video);
            videoview.setVideoURI(Uri.parse(vpa));

            //播放
            videoview.start();
            //循环播放
            videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mediaPlayer) {
                    videoview.start();
                    mediaPlayer.setVolume(0f, 0f);
                    float videoRatio = mediaPlayer.getVideoWidth() / (float) mediaPlayer.getVideoHeight();
                    float screenRatio = videoview.getWidth() / (float)
                            videoview.getHeight();
                    float scaleX = videoRatio / screenRatio;
                    if (scaleX >= 1f) {
                        videoview.setScaleX(scaleX);
                    } else {
                        videoview.setScaleY(1f / scaleX);
                    }
                    mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
                        @Override
                        public boolean onInfo(MediaPlayer mp, int what, int extra) {
                            return false;
                        }
                    });
                }
            });
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    @SuppressLint({"WrongConstant", "WrongThread"})
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            Window window = getWindow();

            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS

                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

            window.setStatusBarColor(Color.TRANSPARENT);

            window.setNavigationBarColor(Color.TRANSPARENT);
        }
        setContentView(R.layout.activity_main);
        getAndroiodScreenProperty();
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        File fileEx = this.getExternalFilesDir(null);
        String dir = fileEx.getAbsolutePath() + "/test_abc";
        if (!fileEx.exists()) { // 先根据路径创建文件夹
            fileEx.mkdirs();
        }
//        Button scrz=findViewById(R.id.scrz);
//        scrz.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                throw new RuntimeException("String");
//            }
//        });
        mon = findViewById(R.id.mon);
        da1 = findViewById(R.id.da1);
        da2 = findViewById(R.id.da2);
        da3 = findViewById(R.id.da3);
        da4 = findViewById(R.id.da4);
        da5 = findViewById(R.id.da5);
        da6 = findViewById(R.id.da6);
        da7 = findViewById(R.id.da7);
        for (int i = 0; i < 35; i++) {
            tfla[i] = false;
        }
        TextView tli;
        tlis telis = new tlis();
        for (int i = 0; i < 35; i++) {
            tli = findViewById(id2[i]);
            tli.setOnClickListener(telis);
        }
//        int year = c.get(Calendar.YEAR);
//        String date = day + "/" + (month+1) + "/" + year;
        bacg = findViewById(R.id.bacgr);
        videoview = (BackVideoView) findViewById(R.id.video);
//        Bitmap bitmapv = getNetVideoBitmap(vpa);
//        if(bitmapv != null) {
//            videoview.setBackground(new BitmapDrawable(getResources(), bitmapv));
//        }//        videoview.setVideoURI(Uri.parse(vpa));
////
////        //播放
////        videoview.start();
////        //循环播放
////        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
////            @Override
////            public void onCompletion(MediaPlayer mediaPlayer) {
////                videoview.start();
////                mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
////                    @Override
////                    public boolean onInfo(MediaPlayer mp, int what, int extra) {
////                        return false;
////                    }
////                });
////            }
////        });
//        videoview.setVideoURI(Uri.parse(vpa));
//
//        videoview.requestFocus();
//
//        videoview.start();
//        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//            @Override
//            public void onCompletion(MediaPlayer mediaPlayer) {
//                videoview.start();
//                mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
//                    @Override
//                    public boolean onInfo(MediaPlayer mp, int what, int extra) {
//                        return false;
//                    }
//                });
//            }
//        });
//        videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
//
//            @Override
//
//            public void onPrepared(MediaPlayer mp) {
//
//                mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {
//
//                    @Override
//
//                    public boolean onInfo(MediaPlayer mp, int what, int extra) {
//
//                        if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
//
//                            videoview.setBackgroundColor(Color.TRANSPARENT);
//
//                        }
//
//                        return true;
//
//                    }
//
//                });
//
//            }
//
//        });


        /***/


//        Button dru = findViewById(R.id.dru);
//        dru.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Dialog dlg;
//                Drawable dr = getResources().getDrawable(R.drawable.radius_border1);
//                dlg = new AlertDialog.Builder(MainActivity.this).create();
//                dlg.show();//显示对话框
//                Window window = dlg.getWindow();//获取对话框窗口\
//                window.setGravity(Gravity.CENTER);//设置对话框显示剧中的位置
//                window.setContentView(R.layout.ctlog);//设置对话框布局
//                window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
//
//                window.setBackgroundDrawable(dr);
//                WindowManager.LayoutParams params = dlg.getWindow()
//                        .getAttributes();
////                Display display = getWindowManager().getDefaultDisplay();
////                params.width = (int) (dpToPx(344));
////                        params.width=dpToPx(360);
////                params.dimAmount = 0.0f;
//                dlg.getWindow().setAttributes(params);
////                            mEditTextUserName = (EditText) window.findViewById(R.id.user_name);
////            mUserName = mEditTextUserName.getText().toString();
//                final EditText us = window.findViewById(R.id.user_name);
//                final EditText passw = window.findViewById(R.id.password);
////            mEditTextPassWord = (EditText) window.findViewById(R.id.password);
////            mPassWord = mEditTextPassWord.getText().toString();
//                Button jw = window.findViewById(R.id.jw);
//                jw.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        wlu("http://jwzx.usc.edu.cn:8924/jsxsd/");
//                    }
//                });
//                Button btlo = window.findViewById(R.id.login);
//                btlo.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        String pass = String.valueOf(passw.getText());
//                        String use = String.valueOf(us.getText());
//                        if (lg(use, pass, "123") > 10) ;
//                        else lg(use, pass, "122");
//                    }
//                });
//                final ImageView btc = window.findViewById(R.id.display_password);
//                btc.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        if (isHideFirst) {
//                            btc.setImageResource(R.drawable.open);
//                            HideReturnsTransformationMethod method1 = HideReturnsTransformationMethod.getInstance();
//                            passw.setTransformationMethod(method1);
//                            isHideFirst = false;
//                        } else {
//                            btc.setImageResource(R.drawable.close);
//                            TransformationMethod method = PasswordTransformationMethod.getInstance();
//                            passw.setTransformationMethod(method);
//                            isHideFirst = true;
//                        }
//                        int index = passw.getText().toString().length();
//                        passw.setSelection(index);
//                    }
//                });
//                displayPassword = window.findViewById(R.id.display_password);
//                displayPassword.setImageResource(R.drawable.close);
//                mEditTextPassWord = window.findViewById(R.id.password);
//                TransformationMethod method = PasswordTransformationMethod.getInstance();
//                mEditTextPassWord.setTransformationMethod(method);
//                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
//                StrictMode.setThreadPolicy(policy);
//            }
//        });
//        Button xz=findViewById(R.id.xz);
//        xz.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//            }
//        });
//        Button upd=findViewById(R.id.up);
//        upd.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                wlu("https://www.wolai.com/hz3FvMvm2KvmMjkzrB2nfY");
//            }
//        });
//        Button tj=findViewById(R.id.tj);
//        tj.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                MyAppliacation.getInstance().setHandler(handler);
//                Intent  intent = new Intent(MainActivity.this,tjactivity.class);
//                startActivity(intent);
//            }
//        });
//        Button wid=findViewById(R.id.wid);
//        wid.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//               wlu("https://jingyan.baidu.com/article/6079ad0ebae0a569ff86dbb5.html");
//            }
//        });
//        Button read = findViewById(R.id.read);
//        read.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(MainActivity.this, read.class);
//                startActivity(intent);
//            }
//        });
//        Button jw=findViewById(R.id.jw);
//        jw.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//              wlu("http://jwzx.usc.edu.cn:8924/jsxsd/");
//            }
//        });
//        Button join = findViewById(R.id.join);
//        join.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
////                Intent in=new Intent(Intent.ACTION_VIEW,Uri.parse("https://jq.qq.com/?_wv=1027&k=8KLpCS1v"));
////                in.setClassName(com.tencent.)
//                Intent intent = new Intent();
//                intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3D" + "WTQcL8uBb-jNqDzZcl0TFRTO_B2dTJBj"));
//                // 此Flag可根据具体产品需要自定义，如设置，则在加群界面按返回，返回手Q主界面，不设置，按返回会返回到呼起产品界面    //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
//                try {
//                    startActivity(intent);
//                } catch (Exception e) {
//                    // 未安装手Q或安装的版本不支持
//                }
//            }
//        });
//        TextView ins = findViewById(R.id.ins);
//        TextView ins1 = findViewById(R.id.ins1);
//        TextView ins2 = findViewById(R.id.ins2);
//        TextView ins3 = findViewById(R.id.ins3);
//        String text = "华为机型需要到【手机管家】-【应用启动管理】﹣找到【通知栏课程表】-【关闭自动管理改为手动管理】，关闭后会弹框显示手动管理界面，将手动管理三项管理允许自启动、允许关联启动、允许后台活动都选择开启";
//        String text1 = "VIVO 机型需要到【设置】-【电池】-【后台耗电管理】-【关闭通知栏课程表的智能控制】";
//        String text2 = "小米机型需要在桌面长按【通知栏课程表】图标-点击【应用信息】-【省电策略】-【选择无限制】";
//        String text3 = "OPPO 机型需要到【设置】-【电池】-【应用耗电管理】﹣找到【通知栏课程表】﹣打开【允许完全后台行为】和【允许应用自启动】";
//        Spannable span = new SpannableString(text);
//        Spannable span1 = new SpannableString(text1);
//        Spannable span2 = new SpannableString(text2);
//        Spannable span3 = new SpannableString(text3);
//        //设置字体大小为34和30（单位为物理像素），设置字体为黄色和白色，也可以在colors.xml中引入索引从0~5设置字体的大小为34
//        //Spannable.SPAN_EXCLUSIVE_EXCLUSIVE代表要设置的大小为具体的数值类型
//        // 索引从5~到最后 设置字体大小为span.setSpan(new AbsoluteSizeSpan(30),5,text.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span.setSpan(new ForegroundColorSpan(Color.BLACK), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span.setSpan(new ForegroundColorSpan(Color.BLUE), 7, 48, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span.setSpan(new ForegroundColorSpan(Color.BLACK), 48, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        ins.setText(span);
////        span1.setSpan(new AbsoluteSizeSpan(34), 0, 9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        // 索引从5~到最后 设置字体大小为span.setSpan(new AbsoluteSizeSpan(30),5,text.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span1.setSpan(new ForegroundColorSpan(Color.BLACK), 0, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span1.setSpan(new ForegroundColorSpan(Color.BLUE), 10, text1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        ins1.setText(span1);
//        // 索引从5~到最后 设置字体大小为span.setSpan(new AbsoluteSizeSpan(30),5,text.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span2.setSpan(new ForegroundColorSpan(Color.BLACK), 0, 11, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span2.setSpan(new ForegroundColorSpan(Color.BLUE), 11, text2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        ins2.setText(span2);
//        // 索引从5~到最后 设置字体大小为span.setSpan(new AbsoluteSizeSpan(30),5,text.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span3.setSpan(new ForegroundColorSpan(Color.BLACK), 0, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span3.setSpan(new ForegroundColorSpan(Color.BLUE), 10, text3.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        ins3.setText(span3);

        fr();
        reads();
//        Button share = findViewById(R.id.share);
//        share.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                String data = "";
//                String d1 = "";
//                data = data + fla + " ";
//                data = data + colorcan[0][0] + " ";
//                for (int y = 1; y < 3; y++) {
//                    data = data + ifcolor[y] + " " + grcolor[y] + " ";
//                    for (int x = 0; x < 3; x++) {
//                        data = data + colorcan[y][x] + " ";
//                    }
//                }
//                data = data + colorcan[3][0];
//                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
//                ClipData m = ClipData.newPlainText("Label", data);
//                cm.setPrimaryClip(m);
//                Toast to = Toast.makeText(MainActivity.this, "已复制到剪切板，可将皮肤id分享给好友", Toast.LENGTH_SHORT);
//                to.setGravity(Gravity.CENTER, 0, 0);
//                to.show();
//            }
//        });
        checkNeedPermissions();
        //  jumpStartInterface(this);
        //addRecommendationsWidget();
        // getAutostartSettingIntent(this);
        //getAutostartSettingIntent(this);
// componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");//目前看是通用的
//       selfStartManagerSettingIntent(this);
//        Intent intent = new Intent();
//
//        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        ComponentName  componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.mainscreen.MainScreenActivity");
//        intent.setComponent(componentName);
//        startActivity(intent);

        openBattart(this);

        File cacheFile1 = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file1");

        // 上级文件不存在，进行文件夹的创建
        if (!cacheFile1.exists()) { // 先根据路径创建文件夹
            cacheFile1.mkdirs();
            Drawable drawable = getResources().getDrawable(R.drawable.bg1);

            BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

            Bitmap bitmap = bitmapDrawable.getBitmap();
            File cacheFile2 = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file");
            if (!cacheFile2.exists()) { // 先根据路径创建文件夹
                cacheFile2.mkdirs();
            }
            File cf = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files", "landx.png");
            try {
                FileOutputStream fos = new FileOutputStream(cf);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
                fos.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else ;

//        im1 = findViewById(R.id.back);
//        im2 = findViewById(R.id.fore);
//        WebView w=findViewById(R.id.web);
//        w.setWebViewClient(new WebViewClient(){
//            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request){
//                return  false;
//            }
//        });
//        WebSettings
//        settings = w.getSettings();
//        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
////支持js
//        settings.setJavaScriptEnabled(true);
////        settings.setUserAgentString("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36");
//        settings.setUserAgentString("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36");
//
////自适应屏幕
//        settings.setUseWideViewPort(true);
//        settings.setLoadWithOverviewMode(true);


////自动缩放
//        settings.setBuiltInZoomControls(true);
//        settings.setSupportZoom(true);
////支持获取手势焦点
//        w.requestFocusFromTouch();
//        w.setWebViewClient(new MyWeb());
//        w.loadUrl("http://jwzx.usc.edu.cn:8924/jsxsd/");

//        spinner = (Spinner) findViewById(R.id.Spinner01);
//        //将可选内容与ArrayAdapter连接起来
//        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m);
//
//        //设置下拉列表的风格
//        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//
//        //将adapter 添加到spinner中
//        spinner.setAdapter(adapter);
//
//        //添加事件Spinner事件监听
//        spinner.setOnItemSelectedListener(new SpinnerSelectedListener());
//
//        //设置默认值
//        spinner.setVisibility(View.VISIBLE);
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
//            spinner.setPopupBackgroundResource(R.drawable.ripple);
//            spinner.setDropDownVerticalOffset(dpToPx(50));
//        }
        setc();
        tezh = findViewById(R.id.sele);

        /**Main2Activity*/
        if (make(1, 0) == 1) make(0, 1);
        int e1 = 0;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            e1 = Math.toIntExact(bben);
        }
        //biao
//        spinner.setSelection(e1 - 1);
        final LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
        final GradientDrawable drawable2 = new GradientDrawable();
        drawable2.setShape(GradientDrawable.RECTANGLE);
        drawable2.setGradientType(GradientDrawable.RECTANGLE);
//        drawable2.setCornerRadius(50);
//        Drawable drawable = getResources().getDrawable(R.drawable.bg1);
//
//        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
//
//        Bitmap bitmap = bitmapDrawable.getBitmap();
        Bitmap bitmap = Bitmap.createBitmap(1080, 1738, Bitmap.Config.ARGB_8888);
        bitmap.eraseColor(0xff22737F);
//        bbb = new BitmapDrawable(Main2Activity.toRoundCorner(bitmap, 20));
        bbb = new BitmapDrawable(bitmap);
        if (flazjm != 10) {
            if (flazjm == 8) {
                if (ifcolor[1] == 0) {
                    drawable2.setColor(colorcan[1][0]);
                    System.out.println(88888);
                } else {
                    int[] colors = {colorcan[1][1], colorcan[1][2]};
                    drawable2.setColors(colors);
                    drawable2.setOrientation(or[grcolor[1]]);
                }
                Bitmap zbit = Bitmap.createBitmap(1080, 2400, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(zbit);
                drawable2.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                drawable2.draw(canvas);
                bacg.setImageBitmap(zbit);

            } else {
                Uri imageUri;
                String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
                imageUri = Uri.fromFile(new File(strFilePath, "landxzjm.png"));
                try {
                    bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
//            bitmap=getAlplaBitmap(bitmap,alp);
//            bbb = new BitmapDrawable(Main2Activity.toRoundCorner(bitmap, 100));
//            bbb = new BitmapDrawable(bitmap);
                bacg.setImageBitmap(bitmap);
            }
        }
//        else
//            bacg.setImageBitmap(bitmap);

        /***/
        if (flazjm == 10) {
            Bitmap bitmap5 = Bitmap.createBitmap(1080, 2400, Bitmap.Config.ARGB_8888);
            bitmap5.eraseColor(0x00000000);
            bacg.setImageBitmap(bitmap5);
            Bitmap bitmapv = getNetVideoBitmap(vpa);
            if (bitmapv != null) {
                videoview.setBackground(new BitmapDrawable(getResources(), bitmapv));
            }//        videoview.setVideoURI(Uri.parse(vpa));
//
//        //播放
//        videoview.start();
//        //循环播放
//        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//            @Override
//            public void onCompletion(MediaPlayer mediaPlayer) {
//                videoview.start();
//                mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
//                    @Override
//                    public boolean onInfo(MediaPlayer mp, int what, int extra) {
//                        return false;
//                    }
//                });
//            }
//        });
            videoview.setVideoURI(Uri.parse(vpa));

            videoview.requestFocus();

            videoview.start();
            videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mediaPlayer) {
                    videoview.start();
                    mediaPlayer.setVolume(0f, 0f);
                    float videoRatio = mediaPlayer.getVideoWidth() / (float) mediaPlayer.getVideoHeight();
                    float screenRatio = videoview.getWidth() / (float)
                            videoview.getHeight();
                    float scaleX = videoRatio / screenRatio;
                    if (scaleX >= 1f) {
                        videoview.setScaleX(scaleX);

                    } else {
                        videoview.setScaleY(1f / scaleX);

                    }
                    mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
                        @Override
                        public boolean onInfo(MediaPlayer mp, int what, int extra) {
                            return false;
                        }
                    });
                }
            });
            videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

                @Override

                public void onPrepared(MediaPlayer mp) {
                    mp.setVolume(0f, 0f);
                    float videoRatio = mp.getVideoWidth() / (float) mp.getVideoHeight();
                    float screenRatio = videoview.getWidth() / (float)
                            videoview.getHeight();
                    float scaleX = videoRatio / screenRatio;
                    if (scaleX >= 1f) {
                        videoview.setScaleX(scaleX);
                    } else {
                        videoview.setScaleY(1f / scaleX);
                    }
                    mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {

                        @Override

                        public boolean onInfo(MediaPlayer mp, int what, int extra) {

                            if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {

                                videoview.setBackgroundColor(Color.TRANSPARENT);

                            }

                            return true;

                        }

                    });

                }

            });
        }
//        colorcan[3][0]=0xFFCCF9FE;
        if (ifcolor[2] == 0) {
            int[] cc = {colorcan[2][0], colorcan[2][0]};
//            int[] cc = {0x00000000, 0x00000000};

            for (int i = 0; i < 35; i++) {
                drawable1[i].setShape(GradientDrawable.RECTANGLE);
                drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
                drawable1[i].setCornerRadius(15);
                drawable1[i].setStroke(3, colorcan[3][0]);
                drawable1[i].setColors(cc);
            }
        } else {
            int[] cs = {colorcan[2][1], colorcan[2][2]};
//            int[] cs = {0x00000000, 0x00000000};
            for (int i = 0; i < 35; i++) {
                drawable1[i].setShape(GradientDrawable.RECTANGLE);
                drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
                drawable1[i].setCornerRadius(15);
                drawable1[i].setStroke(3, colorcan[3][0]);
                drawable1[i].setColors(cs);
                drawable1[i].setOrientation(or[grcolor[2]]);
            }
        }

        /**Main2Activity*/

//        ActionBar actionBar = getSupportActionBar();
//        if (actionBar != null) {
//            actionBar.hide();
//        }
//        displayPassword = findViewById(R.id.display_password);
//        displayPassword.setOnClickListener(this);
//        displayPassword.setImageResource(R.drawable.close);
//        mEditTextPassWord = findViewById(R.id.password);
//        TransformationMethod method = PasswordTransformationMethod.getInstance();
//        mEditTextPassWord.setTransformationMethod(method);
//        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
//        StrictMode.setThreadPolicy(policy);
//        simpleNoti = findViewById(R.id.btn_notification_simple);
//        simpleNoti.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                //tzl1
//////tzl2
//                startService();
//                Toast to = Toast.makeText(MainActivity.this, "已发送", Toast.LENGTH_SHORT);
//                to.setGravity(Gravity.CENTER, 0, 0);
//                to.show();
//            }
//        });
//        Button hf = findViewById(R.id.hf);
//        hf.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                String data = "1";
//                String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
//                File cacheFile = new File(strFilePath);
//                // 上级文件不存在，进行文件夹的创建
//                if (!cacheFile.exists()) { // 先根据路径创建文件夹
//                    cacheFile.mkdirs();
//                }
//                String filename = "th2.txt";
//                File file = new File(strFilePath, filename);//在创建文件
//                boolean createResult = false;
//                try {
//                    if (file.exists()) {
//                        file.delete();
//                    }
//                    createResult = file.createNewFile();
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//                file.canWrite();
//                OutputStream ff = null;
//                try {
//                    ff = new FileOutputStream(file);
//                } catch (FileNotFoundException e) {
//                    e.printStackTrace();
//                }
//                byte[] szBuf = data.getBytes();
//                try {
//                    ff.write(szBuf);
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//                try {
//                    ff.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//        ben = findViewById(R.id.ben);
//        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
//            ben.setOnClickListener(new View.OnClickListener() {
//                int e2 = Math.toIntExact(bben);
//
//                public void onClick(View view) {
//                    spinner.setSelection(e2 - 1);
//                    wend = e2;
//                }
//            });
//        }
        Button more = findViewById(R.id.more);
        more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Dialog dlg;
                final Drawable dr = getResources().getDrawable(R.drawable.rd3);
                dlg = new AlertDialog.Builder(MainActivity.this).create();
                dlg.show();//显示对话框
                Window window = dlg.getWindow();//获取对话框窗口\
                window.setGravity(Gravity.BOTTOM);//设置对话框显示剧中的位置
                window.setContentView(R.layout.morect);//设置对话框布局
                window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

                window.setBackgroundDrawable(dr);
                WindowManager.LayoutParams params = dlg.getWindow()
                        .getAttributes();
//                Display display = getWindowManager().getDefaultDisplay();
//                params.width = (int) (dpToPx(344));
//                        params.width=dpToPx(360);
//                params.dimAmount = 0.0f;
                dlg.getWindow().setAttributes(params);
                Button ddiy = window.findViewById(R.id.ddiy);
                ddiy.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        MyAppliacation.getInstance().setHandler(handler);
                        Intent intent = new Intent(MainActivity.this, Main2Activity.class);
                        startActivity(intent);
                        dlg.cancel();
                    }
                });
                Button jjoin = window.findViewById(R.id.joinj);
                jjoin.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dlg.cancel();
                        Intent intent = new Intent();
                        intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3D" + "WTQcL8uBb-jNqDzZcl0TFRTO_B2dTJBj"));
                        // 此Flag可根据具体产品需要自定义，如设置，则在加群界面按返回，返回手Q主界面，不设置，按返回会返回到呼起产品界面    //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        try {
                            startActivity(intent);
                        } catch (Exception e) {
                            // 未安装手Q或安装的版本不支持
                        }
                    }
                });
                Button noti = window.findViewById(R.id.nosim);
                noti.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dlg.cancel();
                        startService();
                        Toast to = Toast.makeText(MainActivity.this, "已发送", Toast.LENGTH_SHORT);
                        to.setGravity(Gravity.CENTER, 0, 0);
                        to.show();
                    }
                });
                Button about = window.findViewById(R.id.gx);
                about.setOnClickListener(new View.OnClickListener() {
                    @RequiresApi(api = Build.VERSION_CODES.O)
                    @Override
                    public void onClick(View view) {
                        dlg.cancel();
//                        addShortCut(MainActivity.this);
//                        createSystemSwitcherShortCut(MainActivity.this);
                        wlu("https://www.wolai.com/hz3FvMvm2KvmMjkzrB2nfY");
//                        Intent actionIntent = new Intent();
//                        actionIntent.setClass(MainActivity.this,MainActivity.class);
//                        actionIntent.setAction(Intent.ACTION_MAIN)
//                                .addCategory(Intent.CATEGORY_LAUNCHER);
//                        Intent addShortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
////图标资源
//                        Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(
//                                MainActivity.this,
//                                R.mipmap.ic_launcher
//                        );
//                        addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,actionIntent)//添加动作
//                                .putExtra(Intent.EXTRA_SHORTCUT_NAME,"Location")//添加文字
//                                .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,icon)//添加图标
//                                .putExtra("duplicate", true);//是否可以重复
//                        sendBroadcast(addShortcutIntent);
//                        ShortcutManager shortcutManager =
//                                MainActivity.this.getSystemService(ShortcutManager.class);
//
//                        if (shortcutManager.isRequestPinShortcutSupported()) {
//                            // Assumes there's already a shortcut with the ID "my-shortcut".
//                            // The shortcut must be enabled.
//                            ShortcutInfo pinShortcutInfo =
//                                    new ShortcutInfo.Builder(MainActivity.this, "my-shortcut").build();
//
//                            // Create the PendingIntent object only if your app needs to be notified
//                            // that the user allowed the shortcut to be pinned. Note that, if the
//                            // pinning operation fails, your app isn't notified. We assume here that the
//                            // app has implemented a method called createShortcutResultIntent() that
//                            // returns a broadcast intent.
//                            Intent pinnedShortcutCallbackIntent =
//                                    shortcutManager.createShortcutResultIntent(pinShortcutInfo);
//
//                            // Configure the intent so that your app's broadcast receiver gets
//                            // the callback successfully.For details, see PendingIntent.getBroadcast().
//                            PendingIntent successCallback = PendingIntent.getBroadcast(MainActivity.this, /* request code */ 0,
//                                    pinnedShortcutCallbackIntent, /* flags */ PendingIntent.FLAG_IMMUTABLE);
//
//                            shortcutManager.requestPinShortcut(pinShortcutInfo,
//                                    successCallback.getIntentSender());
//                        }
//                        Intent target = new Intent();
//                                 target.setClassName(MainActivity.this, MainActivity.this.getClass().getName());
//
//                                 // 动态生成快捷方式
//                                 Intent shortcutIntent = new Intent("com.huawei.android.launcher.dragndrop.AddItemActivity");
//                                 shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "shortcutName");
//                                 shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(MainActivity.this,  R.layout.wid1));
//                                 shortcutIntent.putExtra("duplicate", false);
//                                 shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, target);
//
//                                 // 利用receiver通知系统创建快捷方式
//                                 sendBroadcast(shortcutIntent);
                    }
                });
                Button wid = window.findViewById(R.id.wid);
                wid.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dlg.cancel();
                        final Dialog dlg;
                        final Drawable dr = getResources().getDrawable(R.drawable.rd3);
                        dlg = new AlertDialog.Builder(MainActivity.this).create();
                        dlg.show();//显示对话框
                        Window window = dlg.getWindow();//获取对话框窗口\
                        window.setGravity(Gravity.CENTER);//设置对话框显示剧中的位置
                        window.setContentView(R.layout.wid);//设置对话框布局
                        window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

                        window.setBackgroundDrawable(dr);
                        WindowManager.LayoutParams params = dlg.getWindow()
                                .getAttributes();
//                Display display = getWindowManager().getDefaultDisplay();
//                params.width = (int) (dpToPx(344));
//                        params.width=dpToPx(360);
//                params.dimAmount = 0.0f;
                        dlg.getWindow().setAttributes(params);
                        Button one = window.findViewById(R.id.one);
                        one.setOnClickListener(new View.OnClickListener() {
                            @RequiresApi(api = Build.VERSION_CODES.O)
                            @Override
                            public void onClick(View view) {
                                dlg.cancel();
//                                AppWidgetManager appWidgetManager = MainActivity.this.getSystemService(AppWidgetManager.class);
//                                ComponentName myProvider = new ComponentName(MainActivity.this, MyWidget.class);
////@RequiresApi(api = Build.VERSION_CODES.O)
//                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//                                    if (appWidgetManager.isRequestPinAppWidgetSupported()) {
//                                        // AppWidget创建成功回调
//                                        Intent pinnedWidgetCallbackIntent = new Intent(MainActivity.this, MyWidget.class);
//                                        PendingIntent successCallback = PendingIntent.getBroadcast(MainActivity.this, 0, pinnedWidgetCallbackIntent, PendingIntent.FLAG_IMMUTABLE);
//                                        //如果不需要创建成功回调，requestPinAppWidget的第三个参数可以为null
//                                        appWidgetManager.requestPinAppWidget(myProvider, null, successCallback);
//                                    }
//                                }
                                AppWidgetManager mAppWidgetManager =
                                        MainActivity.this.getSystemService(AppWidgetManager.class);

                                AppWidgetProviderInfo myWidgetProviderInfo = new AppWidgetProviderInfo();
                                ComponentName myProvider = new ComponentName(MainActivity.this, MyWidget.class);
                                if (mAppWidgetManager.isRequestPinAppWidgetSupported()) {
                                    // Create the PendingIntent object only if your app needs to be notified
                                    // that the user allowed the widget to be pinned. Note that, if the pinning
                                    // operation fails, your app isn't notified.
                                    Intent pinnedWidgetCallbackIntent = new Intent(MainActivity.this, MyWidget.class);

                                    // Configure the intent so that your app's broadcast receiver gets
                                    // the callback successfully. This callback receives the ID of the
                                    // newly-pinned widget (EXTRA_APPWIDGET_ID).
                                    PendingIntent successCallback = PendingIntent.getBroadcast(MainActivity.this, 0, pinnedWidgetCallbackIntent, PendingIntent.FLAG_IMMUTABLE);
                                    Bundle extras = new Bundle();
                                    extras.putString("addType", "appWidgetDetail");
                                    // packageName 为应用真实包名
                                    extras.putString("widgetName", "com.lan.schedule/com.lan.schedule.MyWidget");
                                    Bundle dataBundle = new Bundle();
                                    dataBundle.putString("dataKey1", "data1xxx");
                                    dataBundle.putString("dataKey2", "data2xxx");
                                    dataBundle.putString("dataKey3", "data3xxx");
                                    dataBundle.putString("dataKey4", "data4xxx");
                                    dataBundle.putString("dataKey5", "data5xxx");
                                    extras.putBundle("widgetExtraData", dataBundle);
                                    mAppWidgetManager.requestPinAppWidget(myProvider, null,
                                            successCallback);
                                }
                            }
                        });
                        Button two = window.findViewById(R.id.two);
                        two.setOnClickListener(new View.OnClickListener() {
                            @RequiresApi(api = Build.VERSION_CODES.O)
                            @Override
                            public void onClick(View view) {
                                dlg.cancel();
//                                AppWidgetManager appWidgetManager = MainActivity.this.getSystemService(AppWidgetManager.class);
//                                ComponentName myProvider = new ComponentName(MainActivity.this, mywi1.class);
////@RequiresApi(api = Build.VERSION_CODES.O)
//                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//                                    if (appWidgetManager.isRequestPinAppWidgetSupported()) {
//                                        // AppWidget创建成功回调
//                                        Intent pinnedWidgetCallbackIntent = new Intent(MainActivity.this, mywi1.class);
//                                        PendingIntent successCallback = PendingIntent.getBroadcast(MainActivity.this, 0, pinnedWidgetCallbackIntent, PendingIntent.FLAG_IMMUTABLE);
//                                        //如果不需要创建成功回调，requestPinAppWidget的第三个参数可以为null
//                                        appWidgetManager.requestPinAppWidget(myProvider, null, null);
//                                    }
//                                }
                                AppWidgetManager mAppWidgetManager =
                                        MainActivity.this.getSystemService(AppWidgetManager.class);

                                AppWidgetProviderInfo myWidgetProviderInfo = new AppWidgetProviderInfo();
                                ComponentName myProvider = new ComponentName(MainActivity.this, mywi1.class);
                                if (mAppWidgetManager.isRequestPinAppWidgetSupported()) {
                                    // Create the PendingIntent object only if your app needs to be notified
                                    // that the user allowed the widget to be pinned. Note that, if the pinning
                                    // operation fails, your app isn't notified.
                                    Intent pinnedWidgetCallbackIntent = new Intent(MainActivity.this, mywi1.class);

                                    // Configure the intent so that your app's broadcast receiver gets
                                    // the callback successfully. This callback receives the ID of the
                                    // newly-pinned widget (EXTRA_APPWIDGET_ID).
                                    PendingIntent successCallback = PendingIntent.getBroadcast(MainActivity.this, 0, pinnedWidgetCallbackIntent, PendingIntent.FLAG_IMMUTABLE);

                                    mAppWidgetManager.requestPinAppWidget(myProvider, null,
                                            successCallback);
                                }
                            }
                        });
                    }
                });
                Button set = window.findViewById(R.id.set);
                set.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dlg.cancel();
                        final Dialog dlg;
                        final Drawable dr = getResources().getDrawable(R.drawable.rd3);
                        dlg = new AlertDialog.Builder(MainActivity.this).create();
                        dlg.show();//显示对话框
                        Window window = dlg.getWindow();//获取对话框窗口\
                        window.setGravity(Gravity.CENTER);//设置对话框显示剧中的位置
                        window.setContentView(R.layout.date);//设置对话框布局
                        window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

                        window.setBackgroundDrawable(dr);
                        WindowManager.LayoutParams params = dlg.getWindow()
                                .getAttributes();
//                Display display = getWindowManager().getDefaultDisplay();
//                params.width = (int) (dpToPx(344));
//                        params.width=dpToPx(360);
//                params.dimAmount = 0.0f;
                        dlg.getWindow().setAttributes(params);
                        final DatePicker datePicker = window.findViewById(R.id.date);
                        Button ok = window.findViewById(R.id.ok);
                        Button cancel = window.findViewById(R.id.cancel);
                        cancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                dlg.cancel();
                            }
                        });
                        ok.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                int year = datePicker.getYear();
                                int month = datePicker.getMonth() + 1;
                                int dayOfMonth = datePicker.getDayOfMonth();
                                String data = year + "-" + month + "-" + dayOfMonth + " " + "00:00";
                                String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
                                File cacheFile = new File(strFilePath);
                                // 上级文件不存在，进行文件夹的创建
                                if (!cacheFile.exists()) { // 先根据路径创建文件夹
                                    cacheFile.mkdirs();
                                }
                                String filename = "date.txt";

                                File file = new File(strFilePath, filename);//在创建文件
                                boolean createResult = false;
                                try {
                                    if (file.exists()) {
                                        file.delete();
                                    }
                                    createResult = file.createNewFile();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                file.canWrite();
                                OutputStream ff = null;
                                try {
                                    ff = new FileOutputStream(file);
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                }
                                byte[] szBuf = data.getBytes();
                                try {
                                    ff.write(szBuf);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                try {
                                    ff.close();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                if (make(1, 0) == 1) make(0, 1);
                                dlg.cancel();
                            }
                        });
                    }
                });
                Button jiaowu = window.findViewById(R.id.jiaowu);
                jiaowu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dlg.cancel();
                        wlu("http://jwzx.usc.edu.cn:8924/jsxsd/");
                    }
                });
                Button dru = window.findViewById(R.id.daoru);
                dru.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dlg.cancel();
                        String date = null;
                        try {
                            String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
                            File file = new File(strFilePath, "date.txt");//在创建文件
                            file.canRead();
                            InputStream ff = null;
                            ff = new FileInputStream(file);

                            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(ff));
                            date = bufferedReader.readLine();
                            ff.close();
                            bufferedReader.close();
//            ba = ba1;
//            sh = sh1;
//            fo = fo1;
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (date != null) {
                            Drawable dr = getResources().getDrawable(R.drawable.radius_border1);
                            dlg15 = new AlertDialog.Builder(MainActivity.this).create();
                            dlg15.show();//显示对话框
                            Window window = dlg15.getWindow();//获取对话框窗口\
                            window.setGravity(Gravity.CENTER);//设置对话框显示剧中的位置
                            window.setContentView(R.layout.ctlog);//设置对话框布局
                            window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

                            window.setBackgroundDrawable(dr);
                            WindowManager.LayoutParams params = dlg15.getWindow()
                                    .getAttributes();
//                Display display = getWindowManager().getDefaultDisplay();
//                params.width = (int) (dpToPx(344));
//                        params.width=dpToPx(360);
//                params.dimAmount = 0.0f;
                            dlg15.getWindow().setAttributes(params);
//                            mEditTextUserName = (EditText) window.findViewById(R.id.user_name);
//            mUserName = mEditTextUserName.getText().toString();
                            final EditText us = window.findViewById(R.id.user_name);
                            imageView_rc = window.findViewById(R.id.randomcode);
                            imageView_rc.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    new PicThread().start();
                                }
                            });
//                            new Thread(){public void run() {
//                                String url = "http://youneedlan.com:8080/update_schedule_1/updata";
//                                String result = null;
//                                CloseableHttpClient httpClient = HttpClients.createDefault();
//                                try {
//
//                                    HttpRequest httpRequest = new HttpPost(url);
//                                    HttpResponse httpResponse = httpClient.execute((HttpUriRequest) httpRequest);
//                                    if (200 == httpResponse.getStatusLine().getStatusCode()) {
//                                        result = EntityUtils.toString(httpResponse.getEntity());
//                                        System.out.println("取得返回值" + result);
//                                    }
//                                } catch (IOException e) {
//                                    e.printStackTrace();
//                                }
//
//                            }}.start();
                            new PicThread().start();
                            EditText rc_e = window.findViewById(R.id.rc_edit);
                            final EditText passw = window.findViewById(R.id.password);
//            mEditTextPassWord = (EditText) window.findViewById(R.id.password);
//            mPassWord = mEditTextPassWord.getText().toString();
                            Button btlo = window.findViewById(R.id.login);
                            btlo.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    rc = String.valueOf(rc_e.getText());
                                    String pass = String.valueOf(passw.getText());
                                    String use = String.valueOf(us.getText());
                                    if (lg(use, pass, "123") > 10) ;
                                    else lg(use, pass, "122");
                                }
                            });
                            final ImageView btc = window.findViewById(R.id.display_password);
                            btc.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (isHideFirst) {
                                        btc.setImageResource(R.drawable.open);
                                        HideReturnsTransformationMethod method1 = HideReturnsTransformationMethod.getInstance();
                                        passw.setTransformationMethod(method1);
                                        isHideFirst = false;
                                    } else {
                                        btc.setImageResource(R.drawable.close);
                                        TransformationMethod method = PasswordTransformationMethod.getInstance();
                                        passw.setTransformationMethod(method);
                                        isHideFirst = true;
                                    }
                                    int index = passw.getText().toString().length();
                                    passw.setSelection(index);
                                }
                            });
                            displayPassword = window.findViewById(R.id.display_password);
                            displayPassword.setImageResource(R.drawable.close);
                            mEditTextPassWord = window.findViewById(R.id.password);
                            TransformationMethod method = PasswordTransformationMethod.getInstance();
                            mEditTextPassWord.setTransformationMethod(method);
                            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                            StrictMode.setThreadPolicy(policy);
                        } else {
                            Toast to = Toast.makeText(MainActivity.this, "请先设置第一周", Toast.LENGTH_SHORT);
                            to.setGravity(Gravity.CENTER, 0, 0);
                            to.show();
                        }
                    }
                });
            }
        });
//        Button temp=findViewById(R.id.temp);
//        temp.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
//                startActivityForResult(intent, 55500);
//            }
//        });
        TextView sele = findViewById(R.id.sele);
        sele.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Drawable dr = getResources().getDrawable(R.drawable.radius_border1);
                dlgqj[0] = new AlertDialog.Builder(MainActivity.this).create();
                dlgqj[0].show();//显示对话框
                Window window = dlgqj[0].getWindow();//获取对话框窗口\
                window.setGravity(Gravity.BOTTOM);//设置对话框显示剧中的位置
                window.setContentView(R.layout.ctsele);//设置对话框布局
                window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

                window.setBackgroundDrawable(dr);
                WindowManager.LayoutParams params = dlgqj[0].getWindow()
                        .getAttributes();
//                Display display = getWindowManager().getDefaultDisplay();
//                params.width = (int) (dpToPx(344));
//                        params.width=dpToPx(360);
//                params.dimAmount = 0.0f;
                dlgqj[0].getWindow().setAttributes(params);
                boxc boxCheckListener = new boxc();
                for (int i = 0; i < 25; i++) {
//            System.out.println("888");
                    cch[i] = window.findViewById(idbx[i]);
                    cch[i].setOnClickListener(boxCheckListener);
                }
                if (nowdc != 0) {
                    CheckBox chhhc = window.findViewById(nowdc);
                    chhhc.setChecked(true);
                }
            }
        });
        last = findViewById(R.id.last);
        last.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                make1(ww-1);
//                ww--;
//                int e = 0;
//                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
//                    e = Math.toIntExact(ww);
//                }
                if (ww == 1) {
                    Toast to = Toast.makeText(MainActivity.this, "已经是第一周了", Toast.LENGTH_SHORT);
                    to.setGravity(Gravity.CENTER, 0, 0);
                    to.show();
                } else {
                    make(0, ww - 1);
//                    tezh.setText("第" + (ww) + "周");
                }
                //biao
//                spinner.setSelection(e - 2);
            }
        });
        next = findViewById(R.id.next);
        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                make1(ww+1);
//                ww++;
//                int e = 0;
//                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
//                    e = Math.toIntExact(ww);
//                }
                if (ww > 24) {
                    Toast to = Toast.makeText(MainActivity.this, "到最后了", Toast.LENGTH_SHORT);
                    to.setGravity(Gravity.CENTER, 0, 0);
                    to.show();
                } else
                //biao
//                    spinner.setSelection(e);
                {
                    make(0, ww + 1);
//                    tezh.setText("第" + ww + "周");
                }
            }
        });
//        Button zj = findViewById(R.id.zj);
//        zj.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                cropFromGallery();
//            }
//        });
//        Button tou = findViewById(R.id.tou);
//        tou.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                flag1 = 1 - flag1;
//                if (flag1 == 1) {
//                    make(1, 0);
//                } else {
//                    String str2[] = new String[26];
//                    for (int i = 1; i < 26; i++) {
//                        str2[i] = "";
//                    }
//                    Bitmap bw = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
//                    int j = 0;
//                    String name1[] = new String[50];
//                    String loc[] = new String[50];
//                    int week[][] = new int[50][30];
//                    int we[] = new int[50];
//                    int day[] = new int[50];
//                    int jie[] = new int[50];
//                    try {
//                        FileInputStream fileInputStream = openFileInput("test.txt");
//                        FileChannel f2 = fileInputStream.getChannel();
//                        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
//                        j = Integer.parseInt(bufferedReader.readLine());
//                        for (int i = 1; i < j; i++) {
//                            name1[i] = bufferedReader.readLine();
//                            loc[i] = bufferedReader.readLine();
//                            jie[i] = Integer.parseInt(bufferedReader.readLine());
//                            day[i] = Integer.parseInt(bufferedReader.readLine());
//                            we[i] = Integer.parseInt(bufferedReader.readLine());
//                            for (int p = 1; p <= we[i]; p++) {
//                                week[i][p] = Integer.parseInt(bufferedReader.readLine());
//                            }
//                        }
////                    String str = null;
////                    while((str = bufferedReader.readLine()) != null)
////                    {
////                        Toast.makeText(AlarmService.this,str, Toast.LENGTH_SHORT).show();
////                    }
//                        f2.close();
//                        bufferedReader.close();
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                    String eTime = "2022-08-28 00:00";
//                    long nd = 1000 * 24 * 60 * 60 * 7;// 一天的毫秒数
//                    long diff = 0;
//                    long wee = 0;
//                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//                    Date curDate = new Date(System.currentTimeMillis());
//                    String nowtime = simpleDateFormat.format(curDate);
//                    try {
//                        diff = simpleDateFormat.parse(nowtime).getTime() - simpleDateFormat.parse(eTime).getTime();
//                    } catch (ParseException e) {
//                        e.printStackTrace();
//                    }
//                    wee = diff / nd + 1;// 计算周数
//                    wee=wend;
//                    //wee=2;
//                    for (int i = 1; i < 11; i++) {
//                        int fl = 0;
//                        int ji;
//                        ji = i / 2 + 1;
//                        if (i % 2 == 0) ji = ji - 1;
//                        int da;
//                        da = i % 2;
//                        outterLoop:
//                        for (int g = 1; g < j; g++) {
//
//                            if (day[g] == da && jie[g] == ji) {
//                                for (int p = 1; p <= we[g]; p++) {
//                                    if (wee == week[g][p]) {
//                                        fl = 1;
//                                        str2[i] = name1[g] + loc[g];
//                                        break outterLoop;
//                                    }
//                                }
//                            }
//                        }
//                        if (fl == 0) str2[i] = "";
//                    }
//                    for (int o = 1; o < 26; o++) {
//                        te1 = findViewById(id4[o - 1]);
//                        te1.setText(str2[o]);
//                        te1.setTextColor(colorcan[0][0]);
//                        //layout.setTextViewText(id2[o-1],str1[o]);
//                        //notificationLayoutExpanded.setTextColor(id2[o-1],0xFFFFFF);
//                        if (str2[o].equals("")) {
//                            te1.setBackgroundColor(0x00ffffff);
//                        } else {
//                            //notificationLayoutExpanded.setImageViewResource(id1[o-1],R.drawable.radius_border);
//                            te1.setBackground(drawable1[o - 1]);
//                        }
//                    }
//                }
//            }
//        });
//        bc = findViewById(R.id.bc);
//        bc.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                String data = null;
//                fr();
//                data = 777 + "\n" + alp + "\n";
//                for (int y = 0; y < 6; y++) {
//                    data = data + ifcolor[y] + "\n" + grcolor[y] + "\n";
//                    for (int x = 0; x < 3; x++) {
//                        data = data + colorcan[y][x] + "\n";
//                    }
//                }
//                String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
//                File cacheFile = new File(strFilePath);
//                // 上级文件不存在，进行文件夹的创建
//                if (!cacheFile.exists()) { // 先根据路径创建文件夹
//                    cacheFile.mkdirs();
//                }
//                String filename = "th1.txt";
//                File file = new File(strFilePath, filename);//在创建文件
//                boolean createResult = false;
//                try {
//                    if (file.exists()) {
//                        file.delete();
//                    }
//                    createResult = file.createNewFile();
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//                file.canWrite();
//                OutputStream ff = null;
//                try {
//                    ff = new FileOutputStream(file);
//                } catch (FileNotFoundException e) {
//                    e.printStackTrace();
//                }
//                byte[] szBuf = data.getBytes();
//                try {
//                    ff.write(szBuf);
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//                try {
//                    ff.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//                Drawable drawable = getResources().getDrawable(R.drawable.bg1);
//
//                BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
//
//                Bitmap bitmap = bitmapDrawable.getBitmap();
//                File cacheFile2 = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file");
//                if (!cacheFile2.exists()) { // 先根据路径创建文件夹
//                    cacheFile2.mkdirs();
//                }
//                File cf = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files", "landx.png");
//                try {
//                    FileOutputStream fos = new FileOutputStream(cf);
//                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
//                    fos.close();
//                } catch (FileNotFoundException e) {
//                    e.printStackTrace();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//                startService();
//                upp();
//            }
//        });
//        diy = findViewById(R.id.diy);
//        diy.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                MyAppliacation.getInstance().setHandler(handler);
//                Intent intent = new Intent(MainActivity.this, Main2Activity.class);
//                startActivity(intent);
//            }
//        });
    }

    class SpinnerSelectedListener implements AdapterView.OnItemSelectedListener {

        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
                                   long arg3) {
            make(0, arg2 + 1);
            wend = arg2 + 1;
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // make1(bben);
        }
    }

    public static void shareFile(Context context, String fileName) {
        File file = new File(fileName);
        if (null != file && file.exists()) {
            Intent share = new Intent(Intent.ACTION_SEND);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Uri contentUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", file);
                share.putExtra(Intent.EXTRA_STREAM, contentUri);
                share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else {
                share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
            }
            share.setType("text/plain");//此处可发送多种文件
            share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            context.startActivity(Intent.createChooser(share, "发送课程数据"));
        } else {
            Toast.makeText(context, "所要发送的数据不存在", Toast.LENGTH_SHORT).show();
        }
    }

    // 分享内容到第三方应用
    public static void allShare(Context context, String content) {
        Intent intent = new Intent();
        // 设置分享行为
        intent.setAction(Intent.ACTION_SEND);
        // 设置分享内容的类型
        intent.setType("text/plain");
        // 添加分享内容标题
        intent.putExtra(Intent.EXTRA_SUBJECT, "发送课程数据");
        // 添加分享内容
        intent.putExtra(Intent.EXTRA_TEXT, content);
        // 创建分享的 Dialog
        intent = Intent.createChooser(intent, "发送课程数据");
        context.startActivity(intent);
    }

    public int lg(String mun, String mpw, String serid) {
        int al = 0;
        if (mun.equals("")) {
            Toast to = Toast.makeText(MainActivity.this, "请输入学号和密码", Toast.LENGTH_SHORT);
            to.setGravity(Gravity.CENTER, 0, 0);
            to.show();
        } else {
//            String name1[] = new String[50];
//            String loc[] = new String[50];
//            int week[][] = new int[50][30];
//            int we[] = new int[50];
//            int day[] = new int[50];
//            int jie[] = new int[50];
            Map<String, String> param = new HashMap<>();
//            mEditTextUserName = (EditText) findViewById(R.id.user_name);
//            mUserName = mEditTextUserName.getText().toString();

//            mEditTextPassWord = (EditText) findViewById(R.id.password);
//            mPassWord = mEditTextPassWord.getText().toString();
            String encoded = "";//加密信息
            j = 1;
            try {
                encoded = Base64EncodeUtils.encryptBASE64(mun.getBytes()) + "%%%" + Base64EncodeUtils.encryptBASE64(mpw.getBytes());
            } catch (Exception e) {
                e.printStackTrace();
            }
            param.put("userAccount", mun);
            param.put("userPassword", mpw);
            param.put("RANDOMCODE", rc);
            param.put("encoded", encoded);
            CloseableHttpClient httpClient2 = HttpClients.createDefault();
            CloseableHttpResponse response2 = null;
            String pp = null;
            try {
                // 创建Http Post请求
                HttpGet httpGet = new HttpGet("http://jwzx.usc.edu.cn:8924/jsxsd/");
                //请求头
                httpGet.addHeader("Cookie", "SERVERID=" + serid);
                httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36");
                httpGet.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
                httpGet.addHeader("Connection", "keep-alive");
                // 执行http请求
                HttpClientContext context = HttpClientContext.create();
                response2 = httpClient2.execute(httpGet, context);
                //获取Cookie信息,得到两个参数 JSESSIONID 、 BIGipServerpool_qzjw
                List<Cookie> cookies = context.getCookieStore().getCookies();
//                for (Cookie cookie : cookies) {
//                    String name = cookie.getName();
//                    String value = cookie.getValue();
//                    pp = value;      // System.out.println(pp);
//
//                    // System.out.println("name:"+name+","+value);
//                }


            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    response2.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            List<URI> redirectLocations = null;
            // 创建Httpclient对象
            CloseableHttpClient httpClient = HttpClients.createDefault();
            CloseableHttpResponse response = null;
            String resultString = "";
            String ii = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                pp = cookie.getOrDefault("JSESSIONID", "");
            }
            try {
                // 创建Http Post请求
                HttpPost httpPost = new HttpPost("http://jwzx.usc.edu.cn:8924/jsxsd/xk/LoginToXk");
                //请求头
                httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                httpPost.addHeader("Cookie", "JSESSIONID=" + pp + "; SERVERID=" + serid);
                // 创建参数列表
                if (param != null) {
                    List<NameValuePair> paramList = new ArrayList<>();
                    for (String key : param.keySet()) {
                        paramList.add(new BasicNameValuePair(key, param.get(key)));
                    }
                    // 模拟表单登录
                    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
                    httpPost.setEntity(entity);
                }

                // 执行http请求
                HttpClientContext context = HttpClientContext.create();
                response = httpClient.execute(httpPost, context);

                //获取Cookie信息,得到两个参数 JSESSIONID 、 BIGipServerpool_qzjw
                List<Cookie> cookies = context.getCookieStore().getCookies();
                for (Cookie cookie : cookies) {
                    String name = cookie.getName();
                    String value = cookie.getValue();
                    if (value.equals("" + serid)) {
                    } else {
                        ii = value;
                    }
                    //  System.out.println("name:"+name+","+value);
                }


            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    response.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            CloseableHttpClient httpClient1 = HttpClients.createDefault();

            try {
                HttpPost httpGet = new HttpPost("http://jwzx.usc.edu.cn:8924/jsxsd/xskb/xskb_list.do");
                //增加头信息
                httpGet.addHeader("Cookie", "JSESSIONID=" + pp + "; SERVERID=" + serid);
                httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36");
                httpGet.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
                httpGet.addHeader("Connection", "keep-alive");
                Map<String, String> param1 = new HashMap<>();
                param1.put("xnxq01id", "2022-2023-2");
                if (param1 != null) {
                    List<NameValuePair> paramList = new ArrayList<>();
                    for (String key : param1.keySet()) {
                        paramList.add(new BasicNameValuePair(key, param1.get(key)));
                    }
                    // 模拟表单登录
                    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
                    httpGet.setEntity(entity);
                }
                //执行
                CloseableHttpResponse response1 = httpClient1.execute(httpGet);
                String html = EntityUtils.toString(response1.getEntity(), "utf8");

//                String html =;

//                allShare(this, html);


//                String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
//                File cacheFile = new File(strFilePath);
//                // 上级文件不存在，进行文件夹的创建
//                if (!cacheFile.exists()) { // 先根据路径创建文件夹
//                    cacheFile.mkdirs();
//                }
//                String filename = "html.txt";
//
//                File file = new File(strFilePath, filename);//在创建文件
//                boolean createResult = false;
//                try {
//                    if (file.exists()) {
//                        file.delete();
//                    }
//                    createResult = file.createNewFile();
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//                file.canWrite();
//                OutputStream ff = null;
//                try {
//                    ff = new FileOutputStream(file);
//                } catch (FileNotFoundException e) {
//                    e.printStackTrace();
//                }
//                byte[] szBuf = html.getBytes();
//                try {
//                    ff.write(szBuf);
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//                try {
//                    ff.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//                shareFile(this,String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th"+"/html.txt");
                //解析html
                Document parse = Jsoup.parse(html);
                Elements select = parse.select("div.kbcontent");
                String text = select.text();
                String[] s = text.split(" ");
                al = s.length;
                System.out.println("88888888" + 1 + s.length + 777);
                int a[] = new int[100];
                int num = 1;
                int nu[] = new int[500];
                for (int i = 1; i < s.length; i++) {
                    if (s[i].equals(" ")) {
                        num++;
                    }
                    if (s[i].equals("教学资料")) {
                        a[j] = i - 4;
                        if (i - 5 > -1 && !(s[i - 5].equals("---------------------")) && (!(i - 6 > -1 && s[i - 6].equals("---------------------")))) {
                            num++;
                        }
                        nu[j] = num;
                        System.out.println(nu[j]);

                        System.out.println(s[i - 4]);
                        j++;
                    }
                    System.out.println(s[i]);
                    System.out.println(i);
                }
                System.out.println(j);

                for (int i = 1; i < j; i++) {
                    name1[i] = s[a[i]];
                    if (name1[i].charAt(0) == '(') name1[i] = s[a[i] - 1] + name1[i];
                    loc[i] = s[a[i] + 3];
                    day[i] = nu[i] % 7;
                    jie[i] = nu[i] / 7 + 1;
                    if (day[i] == 0) {
                        jie[i] = jie[i] - 1;
                    }
                    int ok = 1;
                    int q = 1;
                    week[i][1] = Integer.parseInt(String.valueOf(s[a[i] + 2].charAt(0)));
                    if (!(String.valueOf(s[a[i] + 2].charAt(1)).equals(",")) && !(String.valueOf(s[a[i] + 2].charAt(1)).equals("-")) && !(String.valueOf(s[a[i] + 2].charAt(1)).equals("("))) {
                        week[i][1] = Integer.parseInt(String.valueOf(s[a[i] + 2].charAt(0))) * 10 + Integer.parseInt(String.valueOf(s[a[i] + 2].charAt(1)));
                        q++;
                    }
                    int j1 = 2;
                    for (; q < 1000; q++) {
                        if (String.valueOf(s[a[i] + 2].charAt(q)).equals("(")) {
                            break;
                        } else {
                            if (String.valueOf(s[a[i] + 2].charAt(q)).equals(",")) {
                            } else {
                                if (String.valueOf(s[a[i] + 2].charAt(q)).equals("-")) {
                                } else {
                                    if (String.valueOf(s[a[i] + 2].charAt(q - 1)).equals(",")) {
                                        if (!(String.valueOf(s[a[i] + 2].charAt(q + 1)).equals(",")) && !(String.valueOf(s[a[i] + 2].charAt(q + 1)).equals("-")) && !(String.valueOf(s[a[i] + 2].charAt(q + 1)).equals("("))) {
                                            week[i][j1] = Integer.parseInt(String.valueOf(s[a[i] + 2].charAt(q))) * 10 + Integer.parseInt(String.valueOf(s[a[i] + 2].charAt(q + 1)));
                                            j1++;
                                            q++;
                                        } else {
                                            week[i][j1] = Integer.parseInt(String.valueOf(s[a[i] + 2].charAt(q)));
                                            j1++;
                                        }
                                    } else {
                                        int n1;
                                        if (!(String.valueOf(s[a[i] + 2].charAt(q + 1)).equals(",")) && !(String.valueOf(s[a[i] + 2].charAt(q + 1)).equals("-")) && !(String.valueOf(s[a[i] + 2].charAt(q + 1)).equals("("))) {
                                            n1 = Integer.parseInt(String.valueOf(s[a[i] + 2].charAt(q))) * 10 + Integer.parseInt(String.valueOf(s[a[i] + 2].charAt(q + 1)));
                                            q++;
                                        } else {
                                            n1 = Integer.parseInt(String.valueOf(s[a[i] + 2].charAt(q)));
                                        }
                                        n1 = n1 - week[i][j1 - 1];
                                        for (int i1 = 0; i1 < n1; i1++) {
                                            week[i][j1] = week[i][j1 - 1] + 1;
                                            j1++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    we[i] = j1 - 1;
                }


            } catch (Exception e) {

            }
//            int max=0;
//            for(int i=1;i<j;j++){
//              if(week[i][we[i]]>max)max=week[i][we[i]];
//            }
            String data = j + "\n";
            for (int i = 1; i < j; i++) {
                data = data + name1[i] + "\n" + loc[i] + "\n" + jie[i] + "\n" + day[i] + "\n" + we[i] + "\n";
                for (int p = 1; p <= we[i]; p++) {
                    data = data + week[i][p] + "\n";
                }
            }


            try {
                FileOutputStream fileOutputStream = openFileOutput("test.txt", 0);
                fileOutputStream.write(data.getBytes());
                fileOutputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (al > 10) {
                dlg15.cancel();
                if (make(1, 0) == 1) make(0, 1);
                startService();
                Toast to = Toast.makeText(MainActivity.this, "导入成功，并且已为您将课程表发送到通知栏(・ω< )★", Toast.LENGTH_SHORT);
                to.setGravity(Gravity.CENTER, 0, 0);
                to.show();
            }
        }
        return al;
    }

//
//    public void LogIn(View view) throws IOException {
//       if(lg("123")>10);else lg("122");
//    }

    //获取手机类型
    private static String getMobileType() {
        return Build.MANUFACTURER;
    }

    /**
     * GoTo Open Self Setting Layout
     * Compatible Mainstream Models 兼容市面主流机型
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
//            case R.id.display_password: {
//                if (isHideFirst) {
//                    displayPassword.setImageResource(R.drawable.open);
//                    HideReturnsTransformationMethod method1 = HideReturnsTransformationMethod.getInstance();
//                    mEditTextPassWord.setTransformationMethod(method1);
//                    isHideFirst = false;
//                } else {
//                    displayPassword.setImageResource(R.drawable.close);
//                    TransformationMethod method = PasswordTransformationMethod.getInstance();
//                    mEditTextPassWord.setTransformationMethod(method);
//                    isHideFirst = true;
//                }
//                int index = mEditTextPassWord.getText().toString().length();
//                mEditTextPassWord.setSelection(index);
//                break;
//            }
            default:
                break;
        }
    }

    // 简单通知

    // 设置 pendingIntent


    // 解析 Intent

}